views:

217

answers:

2

GIVEN that you have a fixed area of memory already allocated that you would like to use, what C or C++ libraries will allow you to store a dynamic structure (e.g. a hash) in that memory?

i.e. the hash library must not contain any calls to malloc or new, but must take a parameter that tells it the location and size of the memory it is permitted to use.

(bonus if the library uses offsets rather than pointers internally, in case the shared memory is mapped to different address spaces in each process that uses it)

+7  A: 

You can write your own custom allocators for STL containers.

Dr.Dobb's: What Are Allocators Good For?

SO: Compelling examples of custom C++ STL allocators?

alex vasi
+2  A: 

It's trivial to adapt a simple linear probing hash table to use a block of memory - just set its table(s) to point at the allocated memory when you create it, and don't implement anything to allocate more memory to let the table grow.

Pete Kirkham
I have one of those (as you say: quite trivial to create, especially if you don't need to delete items) but using a proper library might give better performance
OJW