| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# GaudiUtils::Allocator< Type > Class Template Reference

`#include <GaudiKernel/Allocator.h>`

Collaboration diagram for GaudiUtils::Allocator< Type >:

[legend]
List of all members.

## Detailed Description

### template<class Type>
class GaudiUtils::Allocator< Type >

Allocator.

The class is importen from Geant4 project

Date:
  2006-02-10

Definition at line 74 of file Allocator.h.

## Public Types
typedef Type | value_type
typedef size_t | size_type
typedef ptrdiff_t | difference_type
typedef Type * | pointer
typedef const Type * | const_pointer
typedef Type & | reference
typedef const Type & | const_reference
## Public Member Functions
| Allocator () throw ()
| Constructor.
| ~Allocator () throw ()
| destructor
Type * | MallocSingle ()
| Malloc and Free methods to be used when overloading new and delete operators in the client <Type> object.
void | FreeSingle (Type *anElement)
void | ResetStorage ()
| Returns allocated storage to the free store, resets allocator and page sizes.
size_t | GetAllocatedSize () const
| Returns the size of the total memory allocated.
template<class U>
| Allocator (const Allocator< U > &right) throw ()
| Copy constructor.
pointer | address (reference r) const
| Returns the address of values.
const_pointer | address (const_reference r) const
pointer | allocate (size_type n, void *hint=0)
| Allocates space for n elements of type Type, but does not initialise.
void | deallocate (pointer p, size_type n)
| Deallocates n elements of type Type, but doesn't destroy.
void | construct (pointer p, const Type &val)
| Initialises *p by val.
void | destroy (pointer p)
| Destroy *p but doesn't deallocate.
size_type | max_size () const throw ()
| Returns the maximum number of elements that can be allocated.
## Private Attributes
GaudiUtils::AllocatorPool | mem
## Classes
struct | rebind

## Member Typedef Documentation

template<class Type>

typedef Type GaudiUtils::Allocator< Type >::value_type

Definition at line 108 of file Allocator.h.

template<class Type>

typedef size_t GaudiUtils::Allocator< Type >::size_type

Definition at line 109 of file Allocator.h.

template<class Type>

typedef ptrdiff_t GaudiUtils::Allocator< Type >::difference_type

Definition at line 110 of file Allocator.h.

template<class Type>

typedef Type* GaudiUtils::Allocator< Type >::pointer

Definition at line 111 of file Allocator.h.

template<class Type>

typedef const Type* GaudiUtils::Allocator< Type >::const_pointer

Definition at line 112 of file Allocator.h.

template<class Type>

typedef Type& GaudiUtils::Allocator< Type >::reference

Definition at line 113 of file Allocator.h.

template<class Type>

typedef const Type& GaudiUtils::Allocator< Type >::const_reference

Definition at line 114 of file Allocator.h.

## Constructor & Destructor Documentation

template<class Type>

GaudiUtils::Allocator< Type >::Allocator | ( |  | ) | throw ()

Constructor.

Definition at line 188 of file Allocator.h.

    00189   : mem(sizeof(Type))
    00190 {
    00191 }

template<class Type>

GaudiUtils::Allocator< Type >::~Allocator | ( |  | ) | throw ()

destructor

Definition at line 198 of file Allocator.h.

    00199 {
    00200 }

template<class Type>
template<class U>

GaudiUtils::Allocator< Type >::Allocator | ( | const Allocator< U > & | right | ) | throw ()`[inline]`

Copy constructor.

Definition at line 118 of file Allocator.h.

    00119       : mem(right.mem) {}

## Member Function Documentation

template<class Type>

Type * GaudiUtils::Allocator< Type >::MallocSingle | ( |  | ) | `[inline]`

Malloc and Free methods to be used when overloading new and delete operators in the client <Type> object.

Definition at line 207 of file Allocator.h.

References GaudiUtils::AllocatorPool::Alloc(), and GaudiUtils::Allocator< Type >::mem.

Referenced by GaudiUtils::Allocator< Type >::allocate().

    00208 {
    00209   return static_cast<Type*>(mem.Alloc());
    00210 }

template<class Type>

void GaudiUtils::Allocator< Type >::FreeSingle | ( | Type * | anElement | ) | `[inline]`

Definition at line 217 of file Allocator.h.

References GaudiUtils::AllocatorPool::Free(), and GaudiUtils::Allocator< Type >::mem.

Referenced by GaudiUtils::Allocator< Type >::deallocate().

    00218 {
    00219   mem.Free(anElement);
    00220   return;
    00221 }

template<class Type>

void GaudiUtils::Allocator< Type >::ResetStorage | ( |  | ) | `[inline]`

Returns allocated storage to the free store, resets allocator and page sizes.

Note: contents in memory are lost using this call !

Definition at line 228 of file Allocator.h.

References GaudiUtils::Allocator< Type >::mem, and GaudiUtils::AllocatorPool::Reset().

    00229 {
    00230   // Clear all allocated storage and return it to the free store
    00231   //
    00232   mem.Reset();
    00233   return;
    00234 }

template<class Type>

size_t GaudiUtils::Allocator< Type >::GetAllocatedSize | ( |  | ) | const`[inline]`

Returns the size of the total memory allocated.

Definition at line 241 of file Allocator.h.

References GaudiUtils::Allocator< Type >::mem, and GaudiUtils::AllocatorPool::Size().

    00242 {
    00243   return mem.Size();
    00244 }

template<class Type>

pointer GaudiUtils::Allocator< Type >::address | ( | reference | r | ) | const`[inline]`

Returns the address of values.

Definition at line 122 of file Allocator.h.

    00122 { return &r; }

template<class Type>

const_pointer GaudiUtils::Allocator< Type >::address | ( | const_reference | r | ) | const`[inline]`

Definition at line 123 of file Allocator.h.

    00123 { return &r; }

template<class Type>

pointer GaudiUtils::Allocator< Type >::allocate | ( | size_type | n,
|  | void * | hint = `0` |
| ) |  |  | `[inline]`

Allocates space for n elements of type Type, but does not initialise.

Definition at line 126 of file Allocator.h.

References GaudiUtils::Allocator< Type >::MallocSingle().

    00127     {
    00128       // Allocates space for n elements of type Type, but does not initialise
    00129       //
    00130       Type* mem_alloc = 0;
    00131       if (n == 1)
    00132         mem_alloc = MallocSingle();
    00133       else
    00134         mem_alloc = static_cast<Type*>(::operator new(n*sizeof(Type)));
    00135       return mem_alloc;
    00136     }

template<class Type>

void GaudiUtils::Allocator< Type >::deallocate | ( | pointer | p,
|  | size_type | n |
| ) |  |  | `[inline]`

Deallocates n elements of type Type, but doesn't destroy.

Definition at line 139 of file Allocator.h.

References GaudiUtils::Allocator< Type >::FreeSingle().

    00140     {
    00141       // Deallocates n elements of type Type, but doesn't destroy
    00142       //
    00143       if (n == 1)
    00144         FreeSingle(p);
    00145       else
    00146         ::operator delete((void*)p);
    00147       return;
    00148     }

template<class Type>

void GaudiUtils::Allocator< Type >::construct | ( | pointer | p,
|  | const Type & | val |
| ) |  |  | `[inline]`

Initialises *p by val.

Definition at line 151 of file Allocator.h.

    00151 { new((void*)p) Type(val); }

template<class Type>

void GaudiUtils::Allocator< Type >::destroy | ( | pointer | p | ) | `[inline]`

Destroy *p but doesn't deallocate.

Definition at line 153 of file Allocator.h.

    00153 { p->~Type(); }

template<class Type>

size_type GaudiUtils::Allocator< Type >::max_size | ( |  | ) | const throw ()`[inline]`

Returns the maximum number of elements that can be allocated.

Definition at line 156 of file Allocator.h.

    00157     {
    00158       // Returns the maximum number of elements that can be allocated
    00159       //
    00160       return 2147483647/sizeof(Type);
    00161     }

## Member Data Documentation

template<class Type>

GaudiUtils::AllocatorPool GaudiUtils::Allocator< Type >::mem`[private]`

Definition at line 169 of file Allocator.h.

Referenced by GaudiUtils::Allocator< Type >::FreeSingle(), GaudiUtils::Allocator< Type >::GetAllocatedSize(), GaudiUtils::Allocator< Type >::MallocSingle(), and GaudiUtils::Allocator< Type >::ResetStorage().

The documentation for this class was generated from the following file:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiKernel/v25r2/GaudiKernel/Allocator.h