ATLAS Offline Software
Loading...
Searching...
No Matches
ArenaSharedHeapSTLAllocator.h File Reference

STL-style allocator wrapper for ArenaHeapAllocator allowing the heap to be shared between containers. More...

Include dependency graph for ArenaSharedHeapSTLAllocator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  SG::ArenaSharedHeapSTLHeader
 Common header class for ArenaSharedHeapSTLAllocator. More...
class  SG::ArenaSharedHeapSTLAllocator< T >
 Forward declaration. More...
struct  SG::ArenaSharedHeapSTLAllocator< T >::rebind< U >
 Standard STL allocator rebinder. More...

Namespaces

namespace  SG
 Forward declaration.

Functions

template<class T>
void SG::swap (ArenaSharedHeapSTLAllocator< T > &a, ArenaSharedHeapSTLAllocator< T > &b)
template<class T>
void SG::maybeUnprotect (ArenaSharedHeapSTLAllocator< T > &a)
 Hook for unprotecting an arena.

Detailed Description

STL-style allocator wrapper for ArenaHeapAllocator allowing the heap to be shared between containers.

Author
scott snyder snyde.nosp@m.r@bn.nosp@m.l.gov
Date
Nov, 2011

This class defines a STL-style allocator for types T with the following special properties.

  • We use an ArenaHeapAllocator for allocations.
  • Only one object at a time may be allocated.
  • The memory from several allocators may be grouped together in the same memory pool.

So, this allocator is suitable for an STL container which allocates lots of fixed-size objects, such as std::list, and further, you want to be able to have multiple list instances use the same pool.

Note that this allocator will not work for containers that make variable-sized allocations, such as vector and the hash table containers.

To use it, you should first explicitly create the allocator class, and then pass it to the constructors of the containers. The memory pool will be deleted when the original allocator instance is deleted. Example:

{
typedef std::list<int> list_t;
alloc_t allocator;
list_t list1 (allocator);
list_t list2 (allocator);
... Now list1 and list2 will both use the same memory pool.
}
... The memory pool is freed when the object `allocator' is deleted.
pool namespace
Definition libname.h:15

Implementation: Each allocator references a Header object, which is common to all allocators in the pool. When an allocator is copied, the header pointer is copied too. The Header object remembers the address of the allocator which originally created it, so that we can clean things up when that allocator goes away.

A Header contains a list of ArenaHeapAllocator objects, one per payload type. We use ArenaAllocatorRegistry to assign indices to the different allocator types.

Definition in file ArenaSharedHeapSTLAllocator.h.