views:

124

answers:

1

Hi,

In Windows, for very demanding applications, a programmer may use HeapCreate, HeapAlloc in order to better manage and control the allocation of memory- speed it up (aka private allocators). What is the equivalent in Linux c++ programming?

+1  A: 

If you want to use your own private allocator, then use mmap() to map an amount of memory into your process, then you can use that memory as you like. Open a file descriptor to /dev/zero, and then use that as the 'fildes' parameter to mmap(). See man mmap for full details of the parameters to pass. In this respect mmap() plays the same role as HeapCreate().

psmears
You don't need to open `/dev/zero` - you can just use the `MAP_ANONYMOUS` flag and pass -1 as the `fd` argument.
caf
True, and it's often faster if you do, though `MAP_ANONYMOUS` is less portable (e.g. it's not included in SUSv2). But you're right, it would almost certainly do in this situation :-)
psmears