YetiSim Blog

Blogs about simulation and developing YetiSim.

Pointer Containers ptr_vector and ptr_set

I have been extracting components from YetiSim and contributing them to tbbcommunity.org, which is a site that will store extensions to TBB’s own code.  The intention of tbbcommunity.org is to form a symbiotic relationship with the main TBB site.  Ideally tbbcommunity.org will host extra components which are not of sufficient generality or stability for inclusion with official TBB.  In my mind, I would like tbbcommunity.org to become something like the Boost libraries.  Libraries which are not included with the standard releases, but which are indispensable resources.

Anyways, enough about that and on to pointer containers!  The basic motivation for pointer containers within YetiSim is one of exception safety.  I needed a place to safely store pointers to allocated memory, without the use of smart pointers.  Boost shared_ptr is an excellent resource, however it is too slow for YetiSim.  I decided to create ownership classes which will actually own the allocated memory, and so be responsible for its proper destruction.  These classes are low-cost so long as they are lightly contested in parallel code since there are some mutexes within the code.  It has been pointed out to me that this is similar in concept to Boost pointer containers, although my classes are slightly difference since they use TBB mutexes internally.

The basic operations are all documented within the source code (available from tbbcommunity.org’s svn), and I will not repeat them here.  One item worth mentioning is the lack of copy constructor or assignment operator.  It simply does not make sense to copy a container of owned objects from one variable to another.  I could do silly things when the object is assigned to or copied, but this would result in confusing code.  Instead, I simply forbid these operations and instead provide swap().  A user can easily call swap, and its meaning is always clear.  However a user can “assign” one pointer container to another by clearing one container using deleteAll() to ensure memory is properly freed, then calling swap.

I do not provide a method of iterating over the contents of the pointer containers, simply because I do not need it right now.


Posted by AJ Guillon  (March 7, 2008)

One Response to “Pointer Containers ptr_vector and ptr_set”


Leave a Reply