/**** * memory.h * * Interface to the Boehm Garbage Collector. *****/ #ifndef MEMORY_H #define MEMORY_H #include #include #include #include #include #include #ifndef NOHASH #ifndef __GNUC_PREREQ #define __GNUC_PREREQ(maj, min) (0) # endif #if __GNUC_PREREQ(4,3) #include #define EXT std::tr1 #else #define EXT __gnu_cxx #include #define unordered_map hash_map #define unordered_multimap hash_multimap #endif #endif #ifdef __DECCXX_LIBCXX_RH70 #define CONST #else #define CONST const #endif #ifdef USEGC #define GC_THREADS #include #ifdef GC_DEBUG extern "C" { #include } #endif inline void *asy_malloc(size_t n) { #ifdef GC_DEBUG if(void *mem=GC_debug_malloc_ignore_off_page(n, GC_EXTRAS)) #else if(void *mem=GC_malloc_ignore_off_page(n)) #endif return mem; throw std::bad_alloc(); } inline void *asy_malloc_atomic(size_t n) { #ifdef GC_DEBUG if(void *mem=GC_debug_malloc_atomic_ignore_off_page(n, GC_EXTRAS)) #else if(void *mem=GC_malloc_atomic_ignore_off_page(n)) #endif return mem; throw std::bad_alloc(); } #undef GC_MALLOC #undef GC_MALLOC_ATOMIC #define GC_MALLOC(sz) asy_malloc(sz) #define GC_MALLOC_ATOMIC(sz) asy_malloc_atomic(sz) #include #include #else // USEGC using std::allocator; #define gc_allocator allocator class gc {}; class gc_cleanup {}; enum GCPlacement {UseGC, NoGC, PointerFreeGC}; inline void* operator new(size_t size, GCPlacement) { return operator new(size); } inline void* operator new[](size_t size, GCPlacement) { return operator new(size); } template struct GC_type_traits {}; #define GC_DECLARE_PTRFREE(T) \ template<> struct GC_type_traits {} #endif // USEGC namespace mem { #define GC_CONTAINER(KIND) \ template \ struct KIND : public std::KIND >, public gc { \ KIND() : std::KIND >() {} \ KIND(size_t n) : std::KIND >(n) {} \ KIND(size_t n, const T& t) : std::KIND >(n,t) {} \ } GC_CONTAINER(list); GC_CONTAINER(vector); template > struct stack : public std::stack, public gc { }; #undef GC_CONTAINER #define GC_CONTAINER(KIND) \ template > \ struct KIND : public \ std::KIND > >, public gc { \ KIND() : std::KIND > > () {} \ } GC_CONTAINER(map); GC_CONTAINER(multimap); #undef GC_CONTAINER #ifndef NOHASH #define GC_CONTAINER(KIND) \ template , \ typename Eq = std::equal_to > \ struct KIND : public \ EXT::KIND > >, public gc { \ KIND() : EXT::KIND > > () {} \ KIND(size_t n) \ : EXT::KIND > > (n) {} \ } GC_CONTAINER(unordered_map); GC_CONTAINER(unordered_multimap); #undef GC_CONTAINER #undef EXT #endif #ifdef USEGC typedef std::basic_string, gc_allocator > string; typedef std::basic_stringstream, gc_allocator > stringstream; typedef std::basic_istringstream, gc_allocator > istringstream; typedef std::basic_ostringstream, gc_allocator > ostringstream; typedef std::basic_stringbuf, gc_allocator > stringbuf; #else typedef std::string string; typedef std::stringstream stringstream; typedef std::istringstream istringstream; typedef std::ostringstream ostringstream; typedef std::stringbuf stringbuf; #endif // USEGC } // namespace mem #endif