multiple heaps with dlmalloc

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
carbonBased

multiple heaps with dlmalloc

Post by carbonBased »

For ease of development, I'm currently using Doug Lea's malloc as my byte granularity memory allocator.

I'm curious, however, if anybody has hacked this allocator to allow for multiple heaps to allow something like:

void *memoryAllocate(int heapNum, int size);

Where heapNum references various different heaps (perhaps one for basic OS structures, one for shared memory, etc).

I haven't actually looked into what might be required, yet. I'm just curious to know if its been done before, and to perhaps get some advice on it, before actually attempting it.

Thanks,
Jeff
JoeKayzA

Re:multiple heaps with dlmalloc

Post by JoeKayzA »

Hi!

I've once implemented heap support for multiple, seperate heaps. Probably, your heap is described by a set of variables (base address, size, pointer to first non-free block, pointer to first free block...). All you have to do is to pack these into a structure, and then use an instance of this structure for every heap you initialise. When you call malloc, pass it a pointer to such a structure to identify the heap you want to allocate memory from (the 'int heapnum' would work as well, but you'll need a global table of all heaps then). This is how I did it before, for now I've switched to c++, where I will implement heaps as classes. The basic idea is the same, however.

cheers Joe
Post Reply