This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

FIFO using malloc

Hi,

I have to store variable length data in a FIFO.
The main program puches and pops lots of data on/from that FIFO. Data is only pushed
when there is space in in the FIFO-buffer.

Is it a good idea to use dynamic memory allocation (malloc, free) or will I have problems with a growing heap full wasted unusable memory gaps?

Would it be better to store the FIFO in a fixed array and manage the memory for the FIFO-buffer myself?

Suggestions are very welcome.

Kind regards

Luc Vercruysse

  • Just because your data happens to be variable length, doesn't mean you should have a variable-length FIFO. The size of the FIFO should be based on the transfer speed, and how fast your program can pick up the data and process it.

    So the FIFO may in many situations be much smaller than the largest message processed.

    Since you would normally have a fixed-size FIFO, you don't need malloc(). You statically allocate the FIFO buffer when compiling your program.