#include"gc.h" #include <new> // for placement new and bad_alloc
#if !defined(GC_NO_MEMBER_TEMPLATES) && defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC++ 6.0 do not support member templates. # define GC_NO_MEMBER_TEMPLATES #endif
/* First some helpers to allow us to dispatch on whether or not a type *isknowntobepointer-free. *Theseareprivate,exceptthattheclientmayinvokethe *GC_DECLARE_PTRFREEmacro.
*/
GC_DECLARE_PTRFREE(char);
GC_DECLARE_PTRFREE(signedchar);
GC_DECLARE_PTRFREE(unsignedchar);
GC_DECLARE_PTRFREE(signedshort);
GC_DECLARE_PTRFREE(unsignedshort);
GC_DECLARE_PTRFREE(signedint);
GC_DECLARE_PTRFREE(unsignedint);
GC_DECLARE_PTRFREE(signedlong);
GC_DECLARE_PTRFREE(unsignedlong);
GC_DECLARE_PTRFREE(float);
GC_DECLARE_PTRFREE(double);
GC_DECLARE_PTRFREE(longdouble); /* The client may want to add others. */
// In the following GC_Tp is GC_true_type if we are allocating a // pointer-free object. template <class GC_Tp> inlinevoid * GC_selective_alloc(size_t n, GC_Tp, bool ignore_off_page) { void *obj = ignore_off_page ? GC_MALLOC_IGNORE_OFF_PAGE(n) : GC_MALLOC(n); if (0 == obj)
GC_ALLOCATOR_THROW_OR_ABORT(); return obj;
}
#if !defined(__WATCOMC__) /* Note: template-id not supported in this context by Watcom compiler. */ template <> inlinevoid * GC_selective_alloc<GC_true_type>(size_t n, GC_true_type, bool ignore_off_page) { void * obj = ignore_off_page ? GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(n)
: GC_MALLOC_ATOMIC(n); if (0 == obj)
GC_ALLOCATOR_THROW_OR_ABORT(); return obj;
} #endif
// Now the public gc_allocator<T> class. template <class GC_Tp> class gc_allocator { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef GC_Tp* pointer; typedefconst GC_Tp* const_pointer; typedef GC_Tp& reference; typedefconst GC_Tp& const_reference; typedef GC_Tp value_type;
// GC_n is permitted to be 0. The C++ standard says nothing about what // the return value is when GC_n == 0.
GC_Tp* allocate(size_type GC_n, constvoid* = 0) {
GC_type_traits<GC_Tp> traits; returnstatic_cast<GC_Tp *>(GC_selective_alloc(GC_n * sizeof(GC_Tp),
traits.GC_is_ptr_free, false));
}
// GC_n is permitted to be 0. The C++ standard says nothing about what // the return value is when GC_n == 0.
GC_Tp* allocate(size_type GC_n, constvoid* = 0) {
GC_type_traits<GC_Tp> traits; returnstatic_cast<GC_Tp *>(GC_selective_alloc(GC_n * sizeof(GC_Tp),
traits.GC_is_ptr_free, true));
}
/* Note that we currently don't specialize the pointer-free case, since a *pointer-freetraceablecontainerdoesn'tmakethatmuchsense, *thoughitcouldbecomeanissueduetoabstractionboundaries.
*/
// GC_n is permitted to be 0. The C++ standard says nothing about what // the return value is when GC_n == 0.
GC_Tp* allocate(size_type GC_n, constvoid* = 0) { void * obj = GC_MALLOC_UNCOLLECTABLE(GC_n * sizeof(GC_Tp)); if (0 == obj)
GC_ALLOCATOR_THROW_OR_ABORT(); returnstatic_cast<GC_Tp*>(obj);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.