[Gc] Changes to gc_allocator.h

Ben Hutchings ben.hutchings at businesswebsoftware.com
Tue Aug 17 10:25:08 PDT 2004


I've made some local changes to gc_allocator.h and I thought I'd let
people (especially Hans Boehm) know about them in case they're generally
useful.  I can provide patches if they're wanted.

I added GC_DECLARE_PTRFREE invokations for char (*not* the same as
signed
char or unsigned char!), long double, bool, wchar_t, (signed|unsigned)
long long and (signed|unsigned) __int64.  bool and wchar_t would need to
be disabled for older compilers and the non-standard integer types
enabled
only for those compilers that support them.

I made allocate() throw std::bad_alloc if the allocation fails.
Returning
0 is non-standard and will generally result in a crash.  Where
exceptions
are not supported I suggest that it should abort().

I changed allocate() and GC_selective_alloc() calls so that in a debug
build the "filename" passed is the name of the allocator specialisation,
i.e. typeid(gc_allocator).name() or typeid(traceable_allocator).name().
I found this much more useful than "gc_allocator.h".  (The line number
is set to 0 since it's unimportant.)

Some parameter names began with "__", which I changed to "GC_" since
such
names are reserved for the implementation.

I changed destroy() to clear the memory of the destroyed object if it is
not known to be pointer-free.  This is important because containers can
destroy elements without freeing the memory they live in; this is
particularly true of std::vector.  Unless the memory is cleared this can
result in excessive retention of memory.  Unfortunately the standard
does
not require containers to call the allocator's destroy() member so this
doesn't help everywhere.

Finally I changed some names.  Everything moved into namespace gc and
traceable_allocator became no_gc_allocator.

Ben.


More information about the Gc mailing list