peterpi
Posts: 42
Joined: Wed Jan 04, 2012 3:28 pm

Memory management within a malloc'd block.

Fri May 30, 2014 1:33 pm

In Linux, is there a library that takes a large block of memory (e.g. a megabyte returned from malloc), and then carries out allocations and frees from within that larger block? I sometimes work with games consoles whose SDKs come with similar functions, but I can't find anything like that for Linux.

I don't want a fixed-size pool allocator; the allocation requests will not all be the same size.

It's easy enough to write a naive one (e.g. the K&R C book has an example of a first-fit), but I doubt I'm the first person to want to do so.

User avatar
teh_orph
Posts: 346
Joined: Mon Jan 30, 2012 2:09 pm
Location: London
Contact: Website

Re: Memory management within a malloc'd block.

Fri May 30, 2014 2:43 pm

I think this is the classic one; I've used it many times.
AFAIK some OS allocators are built upon it. It's one c file, and it includes mega comments in the header telling you how to use it.
http://g.oswego.edu/dl/html/malloc.html

Customise it the way you want by settings certain includes and off you go. You will want the functions that start with mspace_*.

Return to “C/C++”