[Gc] Using C++ Standard Template Library with GC.
Thu, 30 Oct 2003 10:41:09 -0400
I suppose I also need to explain how to use these allocators.
Normally, you use an STL container like so:
With allocators, you provide the allocator as an additional parameter to the
std::vector<Foo, GC_collectible<Foo> > FooV;
Note the space between the '>' characters - it is required.
This gets to be a mouthful so I typically typedef things:
typedef std::vector<Foo, GC_collectible<Foo> > FooVector;
Now, on GC_collectible vs. GC_atomic: If you don't know what you're doing,
always use GC_collectible. GC_atomic is useful ONLY for std::vector of
non-pointer types such as int and char. The other STL containers use
pointers internally, so GC_atomic is NOT acceptable for these.
(And even std::vector uses pointers in that the typical implementation of a
vector is three pointers into the allocated storage. However, these pointers
are not themselves allocated by any allocator; you can create vectors on the
stack, etc. If you allocate a vector on the heap, or inside a larger
structure, then you must allocate said structure on a collectible heap.)