I need a generic malloc implementation that uses one big fixed-size buffer. Something similar to the "Zero-malloc memory allocator" SQLite has. Do you know of any such implementations? It should be light-weight and portable that can be used for embedded applications.
Thanks in advance.
The SQLite source code is freely available. If you like that a particular implementation, why not use it?
Most current malloc
implementations work by carving up a large chunk of memory they obtained from the OS. If that block runs out, malloc
asks the OS for a new large block.
You could base your own implementation on an existing malloc
implementation (for example the glibc one), and instead of obtaining a block from the OS, you use a single static buffer. When that runs out, malloc
will start failing, just as it does when the OS can't provide any new blocks.