Elsewhere there are things that we all miss, yet it takes just one to notice...

Static memory management

Static memory pool

alternative to malloc()

In a recent project working with the FFMpeg API, I needed a way of allocating memory blocks and freeing them from a static block of memory. The main requirement was that when I closed the stream, I could clean up everything much easier.

When working with FFMpeg you really need to do a lot of memory management manually for video buffers, audio buffers and subtitle buffers. By using a static memory pool for each section, you reduce the chance of memory fragmentation.

After finishing this, I am now using this in other areas too. I will get round to optimising the code so that one version will not rely on the c++ vector class and will just use standard ansi c.

This class can be used as an alternative to malloc() and free(). And there’s no need to worry about freeing up the blocks when it comes to finishing up using the memory.

The simple test to show how it is used:

The header file:

The cpp file:

Scroll to top