Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::base::Allocator Class Referenceabstract

Allocator is an abstract base class for a memory allocator used for Ion objects derived from Allocatable. More...

#include "allocator.h"

Inheritance diagram for ion::base::Allocator:
Collaboration diagram for ion::base::Allocator:

Public Member Functions

void * AllocateMemory (size_t size)
 Allocates memory of the given size. More...
 
void DeallocateMemory (void *p)
 Deallocates a previously-allocated memory block. More...
 
virtual const AllocatorPtrGetAllocatorForLifetime (AllocationLifetime lifetime) const
 Returns the correct Allocator to use to allocate memory with a specific lifetime. More...
 
void SetTracker (const AllocationTrackerPtr &tracker)
 Sets/returns an AllocationTracker instance used to track the workings of this instance. More...
 
const AllocationTrackerPtrGetTracker () const
 
int GetRefCount () const
 GetRefCount() is part of the interface necessary for SharedPtr. More...
 

Protected Member Functions

 Allocator ()
 
 ~Allocator () override
 The destructor is protected because all instances should be managed through SharedPtr. More...
 
virtual void * Allocate (size_t size)=0
 Derived classes must define this to allocate size bytes of memory and return a pointer to it. More...
 
virtual void Deallocate (void *p)=0
 Derived classes must define this to return memory previously allocated by a call to Allocate(). More...
 

Detailed Description

Allocator is an abstract base class for a memory allocator used for Ion objects derived from Allocatable.

The lifetime of an Allocator is managed through AllocatorPtr instances (SharedPtr to an Allocator). Every Allocatable created with an Allocator maintains an AllocatorPtr to that Allocator. Therefore, clients should maintain at least one other AllocatorPtr to an Allocator to prevent it from being destroyed while it is still needed.

Definition at line 61 of file allocator.h.

Constructor & Destructor Documentation

ion::base::Allocator::Allocator ( )
inlineprotected

Definition at line 85 of file allocator.h.

ion::base::Allocator::~Allocator ( )
overrideprotected

The destructor is protected because all instances should be managed through SharedPtr.

Definition at line 25 of file allocator.cc.

Member Function Documentation

virtual void* ion::base::Allocator::Allocate ( size_t  size)
protectedpure virtual

Derived classes must define this to allocate size bytes of memory and return a pointer to it.

The returned memory must make the same alignment guarantee that malloc() makes: the memory is suitably aligned for any kind of variable.

Referenced by AllocateMemory().

virtual void ion::base::Allocator::Deallocate ( void *  p)
protectedpure virtual

Derived classes must define this to return memory previously allocated by a call to Allocate().

Referenced by DeallocateMemory().

void ion::base::Allocator::DeallocateMemory ( void *  p)
const AllocatorPtr & ion::base::Allocator::GetAllocatorForLifetime ( AllocationLifetime  lifetime) const
virtual

Returns the correct Allocator to use to allocate memory with a specific lifetime.

The base class implements this to return the default Allocator for the lifetime from the AllocationManager. Derived classes may override this to provide a different Allocator to support different allocation schemes.

Definition at line 27 of file allocator.cc.

References ion::base::AllocationManager::GetDefaultAllocatorForLifetime().

Referenced by ion::text::Builder::Build(), ion::base::DataContainer::CreateAndCopy(), and ion::base::Allocatable::GetAllocatorForLifetime().

int ion::base::Shareable::GetRefCount ( ) const
inlineinherited

GetRefCount() is part of the interface necessary for SharedPtr.

Definition at line 34 of file shareable.h.

Referenced by ion::base::Notifier::RemoveReceiver().

const AllocationTrackerPtr& ion::base::Allocator::GetTracker ( ) const
inline

Definition at line 82 of file allocator.h.

void ion::base::Allocator::SetTracker ( const AllocationTrackerPtr tracker)
inline

Sets/returns an AllocationTracker instance used to track the workings of this instance.

The pointer is NULL by default, resulting in no tracking. Note that it is probably a bad idea to change the tracker instance while any memory allocated by this instance is still active.

Definition at line 81 of file allocator.h.


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