views:

110

answers:

2

In an embedded program I have a screen object that needs to manage a list of items to display. The initial list of items will be pulled from a simple DB on screen load and the list will be updated via "Add" and "Remove" events. This list needs to be sorted according to certain criteria. I am looking of a container class that can help me accomplish this. Furthermore there is no dynamic memory in the system so I need to have a memory pool of empty items that I can load into container and return to the free pool when I am done with the item.

Anyone know of anything appropriate in the C++ Standard Library or Boost? Or perhaps another solution?

+2  A: 

why not use STL but provide your own allocator and deallocator, for example STL vector is defined as template<class T,class A = std::allocator<T>> vector {}, you can create and set your own allocator that request memory space from your memory pool.

as for memory allocator, you use existing memory allocator such as Hoard http://www.hoard.org/ , or Ned Allocator http://www.nedprod.com/programs/portable/nedmalloc/ which is quite high performance and good for embedded system.

uray
+1  A: 

If you use a standard container (such as std::map or std::set) you need to worry about different dynamic allocations: the allocation of the internal container data structures and the allocation of your own data you want to store in the container. The allocation of the internal data structures can be customized by supplying your own std::allocator (I'm sure you'll be able to find one fitting your needs, there are plenty of those available). The allocation of your own data structures needs to be handled separately, most commonly by implementing type specific new and delete operators. Scott Meyers has a nice article about this in one of his books.

Another solution would be to utilize Boost.Intrusive, a set of containers where all the internal data items needed for the container are stored in your own data structures (that's why they are called intrusive). This relieves you from having two different allocation schemes in place, as you need to worry about your own data allocation only.

hkaiser