TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::AreaMemoryManager Class Reference

Allocates memory in large blocks and then frees it as an area. More...

#include <AreaMemoryManager.h>

Classes

class  Buffer
 

Public Types

typedef shared_ptr
< AreaMemoryManager
Ref
 
- Public Types inherited from G3D::MemoryManager
typedef shared_ptr< class
MemoryManager
Ref
 

Public Member Functions

 ~AreaMemoryManager ()
 
size_t bytesAllocated () const
 
virtual void * alloc (size_t s)
 
virtual void free (void *x)
 
virtual bool isThreadsafe () const
 
void deallocateAll ()
 
- Public Member Functions inherited from G3D::ReferenceCountedObject
virtual ~ReferenceCountedObject ()
 

Static Public Member Functions

static AreaMemoryManager::Ref create (size_t sizeHint=10 *1024 *1024)
 
- Static Public Member Functions inherited from G3D::MemoryManager
static MemoryManager::Ref create ()
 

Private Member Functions

 AreaMemoryManager (size_t sizeHint)
 

Private Attributes

size_t m_sizeHint
 
Array< Buffer * > m_bufferArray
 

Additional Inherited Members

- Protected Member Functions inherited from G3D::MemoryManager
 MemoryManager ()
 

Detailed Description

Allocates memory in large blocks and then frees it as an area.

Useful for ensuring cache coherence and for reducing the time cost of multiple allocations and deallocations.

Not threadsafe

Member Typedef Documentation

Constructor & Destructor Documentation

G3D::AreaMemoryManager::AreaMemoryManager ( size_t  sizeHint)
private
50  : m_sizeHint(sizeHint) {
51  debugAssert(sizeHint > 0);
52 }
size_t m_sizeHint
Definition: AreaMemoryManager.h:51
#define debugAssert(exp)
Definition: debugAssert.h:160

+ Here is the caller graph for this function:

G3D::AreaMemoryManager::~AreaMemoryManager ( )

Invokes deallocateAll.

55  {
56  deallocateAll();
57 }
void deallocateAll()
Definition: AreaMemoryManager.cpp:82

+ Here is the call graph for this function:

Member Function Documentation

void * G3D::AreaMemoryManager::alloc ( size_t  s)
virtual

Allocates memory out of the buffer pool.

Parameters
smust be no larger than sizeHint

Reimplemented from G3D::MemoryManager.

65  {
66  void* n = (m_bufferArray.size() > 0) ? m_bufferArray.last()->alloc(s) : NULL;
67  if (n == NULL) {
68  // This buffer is full
69  m_bufferArray.append(new Buffer(max(s, m_sizeHint)));
70  return m_bufferArray.last()->alloc(s);
71  } else {
72  return n;
73  }
74 }
arena_t NULL
Definition: jemalloc_internal.h:624
T max(const T &x, const T &y)
Definition: g3dmath.h:320
size_t m_sizeHint
Definition: AreaMemoryManager.h:51
Array< Buffer * > m_bufferArray
Definition: AreaMemoryManager.h:54

+ Here is the call graph for this function:

size_t G3D::AreaMemoryManager::bytesAllocated ( ) const
60  {
61  return m_sizeHint * m_bufferArray.size();
62 }
size_t m_sizeHint
Definition: AreaMemoryManager.h:51
Array< Buffer * > m_bufferArray
Definition: AreaMemoryManager.h:54
AreaMemoryManager::Ref G3D::AreaMemoryManager::create ( size_t  sizeHint = 10 * 1024 * 1024)
static
Parameters
sizeHintTotal amount of memory expected to be allocated. The allocator will allocate memory from the system in increments of this size.
45  {
46  return shared_ptr<AreaMemoryManager>(new AreaMemoryManager(sizeHint));
47 }
AreaMemoryManager(size_t sizeHint)
Definition: AreaMemoryManager.cpp:50

+ Here is the call graph for this function:

void G3D::AreaMemoryManager::deallocateAll ( )

Deletes all previously allocated memory. Because delete is not invoked on objects in this memory, it is not safe to simply free memory containing C++ objects that expect their destructors to be called.

82  {
83  m_bufferArray.invokeDeleteOnAllElements();
84  m_bufferArray.clear();
85 }
Array< Buffer * > m_bufferArray
Definition: AreaMemoryManager.h:54

+ Here is the caller graph for this function:

void G3D::AreaMemoryManager::free ( void *  x)
virtual

Ignored.

Reimplemented from G3D::MemoryManager.

77  {
78  // Intentionally empty; we block deallocate
79 }

+ Here is the caller graph for this function:

bool G3D::AreaMemoryManager::isThreadsafe ( ) const
virtual

Returns true if this memory manager is threadsafe (i.e., alloc and free can be called asychronously)

Reimplemented from G3D::MemoryManager.

40  {
41  return false;
42 }

Member Data Documentation

Array<Buffer*> G3D::AreaMemoryManager::m_bufferArray
private

The underlying array is stored in regular MemoryManager heap memory

size_t G3D::AreaMemoryManager::m_sizeHint
private

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