Implementing an STL memory pool with constant memory locations

M

mojumbo

I'm asking for a lot here but what I would like to do is create a
dynamically growing memory pool whose addresses don't change. I
understand I can't do this with std::vector so for the explanation
I'll use an imaginary class called pool.

What I mean:
pool.push_back(object); // Increases memory size by a block size,
say 10 elements

After 10 push_back's

pool.push_back(object); // APPEND 10 additional memory block sizes BUT
elements 1 thru 10 retain their memory locations.

What I'm trying to do:
I am trying to use a tree whose elements maintain a key and a pointer
to the data. That data will reside in a memory pool which grows
dynamically. Don't worry about shrinking.

Any ideas would be gr8.
 
M

mojumbo

*and* the
elements never move in memory (assuming you just push_back() new elements)

This is my biggest concern. I think I'll go with the stl deque.
Thanks all for the replies!
 
J

Jeff Flinn

Juha said:
What's wrong with using std::deque? It's memory-efficient *and* the
elements never move in memory (assuming you just push_back() new elements).

A steadily growing std::vector is a bad idea for a memory allocator
because it causes bad memory fragmentation.

But note that std::deque::iterator is significantly slower than
std::vector::iterator on several implementations.

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top