gatb.core-API-0.0.0
MemoryBounded Class Reference

Implementation of IMemory interface with bounded memory usage. More...

#include <MemoryCommon.hpp>

Inheritance diagram for MemoryBounded:
Inheritance graph

Public Member Functions

 MemoryBounded (IMemoryAllocator &alloc, BlockSize_t maxBlockSize, TotalSize_t maxTotalSize)
 
void * malloc (BlockSize_t size)
 
void * calloc (size_t nmemb, BlockSize_t size)
 
void * realloc (void *ptr, BlockSize_t size)
 
void free (void *ptr)
 
- Public Member Functions inherited from MemorySizeStore
 MemorySizeStore (IMemoryAllocator &alloc)
 
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 bounded memory usage.

This implementation is a Proxy design pattern: it references a memory allocator and checks that client requests doesn't exceed this kind of specifications. If the client request is allowed, the request is done by the referred allocator.

Two thresholds can be parameterize such an allocator at construction:

  • maximum total size allowed
  • maximum block size allowed

Implementation note: in order to ensure that the thresholds are not exceeded, we need to know the size of each allocated pointer. Therefore, when allocating some block of size N, we actually allocate N+d bytes, where d is the size of an integer big enough to represent the requested block size. This size is provided through the class template T.

Constructor & Destructor Documentation

MemoryBounded ( IMemoryAllocator alloc,
BlockSize_t  maxBlockSize,
TotalSize_t  maxTotalSize 
)
inline

Constructor.

Parameters
[in]alloc: the referred IMemoryAllocator instance
[in]maxBlockSize: maximum size allowed for one block allocation
[in]maxTotalSize: maximum size allowed for the sum of blocks allocation

Member Function Documentation

void* calloc ( size_t  nmemb,
BlockSize_t  size 
)
inlinevirtual

See calloc documentation.

Reimplemented from MemorySizeStore.

void free ( void *  ptr)
inlinevirtual

See free documentation.

Reimplemented from MemorySizeStore.

void* malloc ( BlockSize_t  size)
inlinevirtual

See malloc documentation.

Reimplemented from MemorySizeStore.

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

See realloc documentation.

Reimplemented from MemorySizeStore.


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