D
Dan Nilsen
Hi!
I'm writing a small piece of software that basically runs on an
embedded system with a Power-PC cpu. This runs on a stripped down
version of Linux - Busybox.
As I'm writing a piece of code that basically acts as a server and
that will be running for weeks or months and probably even longer,
memory management is a topic that is quite crucial.
Not being a very experienced C programmer, and with next to no help in
the company I currently work in I turn to this forum.
In my program(s), I do have several functions and files as one would
expect.
One of my questions is then: Is it strictly necessary to allocate
memory as in:
BYTE *frame = (BYTE*)malloc(sizeof(BYTE * FRAMELEN); and later to free
this and set the pointer to NULL ? Or can I just allocate the variable
by
BYTE frame[FRAMELEN]; and assume the memory is freed on a function
return?
I'm pretty sure dynamic memory allocation is quite critical in my main
program(the server), in order to avoid any memory leakages.
And as a final question:
If i have code like this:
BYTE *frame = (BYTE*)malloc(sizeof(BYTE * FRAMELEN);
...assign some values to frame...
and then call
free(frame);
frame = NULL;
why do I sometimes get a segmentation fault?
Hope someone has got some good answers for me.
Thanks
Dan Nilsen
I'm writing a small piece of software that basically runs on an
embedded system with a Power-PC cpu. This runs on a stripped down
version of Linux - Busybox.
As I'm writing a piece of code that basically acts as a server and
that will be running for weeks or months and probably even longer,
memory management is a topic that is quite crucial.
Not being a very experienced C programmer, and with next to no help in
the company I currently work in I turn to this forum.
In my program(s), I do have several functions and files as one would
expect.
One of my questions is then: Is it strictly necessary to allocate
memory as in:
BYTE *frame = (BYTE*)malloc(sizeof(BYTE * FRAMELEN); and later to free
this and set the pointer to NULL ? Or can I just allocate the variable
by
BYTE frame[FRAMELEN]; and assume the memory is freed on a function
return?
I'm pretty sure dynamic memory allocation is quite critical in my main
program(the server), in order to avoid any memory leakages.
And as a final question:
If i have code like this:
BYTE *frame = (BYTE*)malloc(sizeof(BYTE * FRAMELEN);
...assign some values to frame...
and then call
free(frame);
frame = NULL;
why do I sometimes get a segmentation fault?
Hope someone has got some good answers for me.
Thanks
Dan Nilsen