Dynamische Speicherallokation

Dynamische Speicherallokation

Prinzip

Zuteilung von Speicher nach Bedarf, da begrenzte Ressouce

malloc: Memory ALLOCation in C

Fehlerbehandlung in C mit malloc

int8_t *foo_with_error_handling(int32_t n){ // to be used 
	int8_t *p;
	// allocate a block of n bytes p
	= (int8_t *) malloc(n); 
	if (p == NULL){ 
		perror("malloc failed while allocating n bytes"); 
		exit(1);
	}
	return p;
}