Malloc and automatic variables

Marcin S msporysz06@gmail.com
Thu Aug 23 11:21:00 GMT 2012


Hello,
I want to use malloc in embedded environment, where there is no memory
management at all - I know it sounds like a bad idea but this malloc
will be called only once somewhere at program start and it wont be
released ever, so memory fragmentation shouldn't be a problem. Unless
there is something i don't know.

Let's assume I have this function

int* vector = 0;
void init(int cnt)
{
   int something = 100;
   vector = malloc(sizeof(int) * cnt);
}

So when above function is called it allocate automatic variable
"something", then allocates memory for vector - after work is done
"something" is freed.
Question is, will I end up with gaping hole in memory between:
(A) memory allocated before this function is called
and
(B) memory allocated by function for vector

###MEMORY_USED_BEFORE###(int sized hole)###MEMORY_FOR_VECTOR###

Or maybe automatic variables are created somewhere else (stack?) and
memory wont be fragmented.
In case it would be significant I'll add that target environment is
ARM Cortex 3.



More information about the Gcc-help mailing list