vector typically doubles the size of memory it reserves when it needs more 
space. This is because every time it allocates new memory it must move the 
contents of the existing memory - it's slow to copy all the existing elements 
and so it makes sense to only increase as few times as possible (see 
http://www.ddj.com/cpp/184401375 for a discussion). 
Unfortunately this isn't a good stratergy when you are almost out of memory.

Another problem is that the memory must be contiguous (ie in one block), so if 
you frequently allocate and delete memory there might not be a single free 
block large enough - even if you have enough overall memory.

There is also a little 'trick' to reduce a vector back down to the minimum 
required memory - see http://www.gotw.ca/gotw/054.htm
 
Code:
vector<stuff>( c ).swap( c );



(note - can someone confirm the swap() trick works with ref counting?)

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=10259#10259





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to