gatb.core-API-1.4.2
MemorySizeStore Class Reference

Implementation of IMemory interface with Proxy design pattern. More...

#include <MemoryCommon.hpp>

Inheritance diagram for MemorySizeStore:
Inheritance graph

Public Member Functions

 MemorySizeStore (IMemoryAllocator &alloc)
 
void * malloc (BlockSize_t size)
 
void * calloc (size_t nmemb, BlockSize_t size)
 
void * realloc (void *ptr, BlockSize_t size)
 
void free (void *ptr)
 
size_t getNbBlocks ()
 
TotalSize_t getCurrentUsage ()
 
TotalSize_t getMaximumUsage ()
 
- Public Member Functions inherited from IMemoryAllocator
virtual ~IMemoryAllocator ()
 

Additional Inherited Members

- Public Types inherited from IMemoryAllocator
typedef u_int64_t BlockSize_t
 
typedef u_int64_t TotalSize_t
 

Detailed Description

Implementation of IMemory interface with Proxy design pattern.

This implementation is a Proxy design pattern: it references a memory allocator and uses this reference for creating memory blocks.

Statistics operations are provided through the IMemory interface. Providing such services implies that we have some management of the allocated blocks. In particular we need to store the size of block which is done by allocating some extra space for each block (this space being used for storing the block size).

Note that such an implementation requires a little bit more memory than clients actually ask for: for instance, if a client calls malloc with 100, the final allocated block size will be 100+4=104 bytes (if sizeof(BlockSize_t)==4).

It is mandatory that blocks created through this implementation are also deleted by the same implementation.

Constructor & Destructor Documentation

MemorySizeStore ( IMemoryAllocator alloc)
inline

Constructor.

Parameters
[in]alloc: the referred memory allocator.

Member Function Documentation

void* calloc ( size_t  nmemb,
BlockSize_t  size 
)
inlinevirtual

See calloc documentation.

Implements IMemoryAllocator.

Reimplemented in MemoryBounded.

void free ( void *  ptr)
inlinevirtual

See free documentation.

Implements IMemoryAllocator.

Reimplemented in MemoryBounded.

TotalSize_t getCurrentUsage ( )
inline

Get the memory usage by the current process.

Returns
the memory usage (in bytes).
TotalSize_t getMaximumUsage ( )
inline

Get the maximum reached size.

Returns
the maximum used memory (in bytes).
size_t getNbBlocks ( )
inline

Get the number of currently allocated memory blocks.

Returns
the number of allocated blocks.
void* malloc ( BlockSize_t  size)
inlinevirtual

See malloc documentation.

Implements IMemoryAllocator.

Reimplemented in MemoryBounded.

void* realloc ( void *  ptr,
BlockSize_t  size 
)
inlinevirtual

See realloc documentation.

Implements IMemoryAllocator.

Reimplemented in MemoryBounded.


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