views:

251

answers:

3

I know that there is an allocator for user applications than handles lots of small block allocation on HP-UX link text and on Windows XP Low-fragmentation Heap. On HP-UX it is possible to tune the allocator and on Windows XP it considers block of size less than 16 K as small.

My problem is that I can't find any information about this kind of allocator for user programs running on Linux (RedHat Linux actually). If there is such an allocator I actually would like to find what maximum size of blocks it can handle.

+1  A: 

As platform independent solution try Boost.Pool Library. It has pool interface that can handle blocks of any size. You can use also pool_alloc which satisfy Standard Allocator requirements.

As platform specific solution you could try mallopt function from glibc library. But as far as I know it will be not helpful for small blocks.

Kirill V. Lyadvinsky
+1  A: 

It's a general-purpose allocator, but the Hoard heap claims to have "strict bounds on fragmentation" [1]:

All of the blocks in a superblock are in the same size class. By using size classes that are a power of b apart (where b is greater than 1) and rounding the requested size up to the nearest size class, we bound worst-case internal fragmentation within a block to a factor of b. In order to reduce external fragmentation, we recycle completely empty superblocks for re-use by any size class.

Dunno if it would help, but it's easy enough to try it out.

Hostile Fork
It is not a default allocator but after testing my application with the Hoard allocator I see that it consumes 17% less memory and runs faster. Thank you!
skwllsp
+1  A: 

Redhat Linux or any Linux based distributions mostly use DL-Malloc (http://gee.cs.oswego.edu/dl/html/malloc.html).

For user applications as Kirill pointed out, better to use separate memory allocators if fragmentation is more because of smaller blocks.

If the user application is small, you can try using C++ placement new/delete which can override the default allocator pattern. (http://en.wikipedia.org/wiki/Placement_syntax)

vprajan