On Wednesday, 29 March 2017 at 19:19:48 UTC, Enigma wrote:
I have a memory buffer allocated using different methods. It is simply a pointer and a size.

I would like to be able to manage this buffer by treating it as a memory pool or heap. I think I can use allocators to do this but not sure how.

Effectively I want something like new or malloc but it pulls from the memory buffer rather than the program heap.

// Allocated once at program start
void* FancyBuffer = FancyAlloc(1000);


Then when I want to use the buffer I'll do stuff like



auto myptr = FancyMalloc(10);

....

FancyFree(myptr);


or whatever.

The main thing is, I don't want to have to write my own allocator to manage this buffer as it seems that D's allocators would do a better job.

I imagine that most of the time the buffer will not have more than one piece of code using it(no overlapping uses) but since I won't be 100% sure, I need allow for the cases where there might be overlapping usage. (else I wouldn't ever have to worry about "allocating or releasing" from it.

Thanks.

It looks like you are looking for this: http://dlang.org/phobos-prerelease/std_experimental_allocator_building_blocks_region.html.

Reply via email to