Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
elm::AbstractBlockAllocatorWithGC Class Referenceabstract

#include <elm/alloc/BlockAllocatorWithGC.h>

+ Inheritance diagram for elm::AbstractBlockAllocatorWithGC:

Classes

struct  free_t
 

Public Member Functions

 AbstractBlockAllocatorWithGC (t::size block_size, t::size chunk_size=1<< 20)
 
virtual ~AbstractBlockAllocatorWithGC (void)
 
void * allocate (void) throw (BadAlloc)
 
void collectGarbage (void)
 
t::size blockSize (void) const
 
t::size chunkSize (void) const
 
int freeCount (void) const
 
int totalCount (void) const
 
int usedCount (void) const
 
void * allocate (t::size size) throw (BadAlloc)
 
void free (void *block)
 

Protected Types

typedef struct
elm::AbstractBlockAllocatorWithGC::free_t 
free_t
 

Protected Member Functions

bool mark (void *ptr)
 
virtual void collect (void)=0
 
virtual void beginGC (void)
 
virtual void endGC (void)
 

Protected Attributes

free_tfree_list
 
int free_cnt
 

Detailed Description

Implements the block allocator whose the template form is BlockAllocatorWithGC.

Member Typedef Documentation

Constructor & Destructor Documentation

elm::AbstractBlockAllocatorWithGC::AbstractBlockAllocatorWithGC ( t::size  block_size,
t::size  chunk_size = 1 << 20 
)

Build the allocator.

Parameters
block_sizeSize of the blocks.
chunk_sizeSize of the memory chunks (1Mb as a default).

References elm::genstruct::Vector< T >::add(), and elm::genstruct::Vector< T >::top().

elm::AbstractBlockAllocatorWithGC::~AbstractBlockAllocatorWithGC ( void  )
virtual

Member Function Documentation

void * elm::AbstractBlockAllocatorWithGC::allocate ( t::size  size)
throw (BadAlloc
)

Allocate a block of the given size. This function accepts as size only the size of elements.

Parameters
sizeSize of the element.
Returns
Allocated block.
Exceptions
BadAllocIf the allocation fails.
void elm::AbstractBlockAllocatorWithGC::beginGC ( void  )
protectedvirtual

Possibly overridden by the actual implementation, called before starting the garbage collection. As a default, do nothing.

Referenced by collectGarbage().

t::size elm::AbstractBlockAllocatorWithGC::blockSize ( void  ) const

Get the block size.

Returns
Block size (in bytes).
t::size elm::AbstractBlockAllocatorWithGC::chunkSize ( void  ) const

Get the memory chunk size.

Returns
Memory chunk size (in bytes).
void elm::AbstractBlockAllocatorWithGC::collect ( void  )
protectedpure virtual

This method must be overridden by the actual implementation of the allocation to perform living block collection, that is, call the mark() method for each living block.

Referenced by collectGarbage().

void elm::AbstractBlockAllocatorWithGC::collectGarbage ( void  )
void elm::AbstractBlockAllocatorWithGC::endGC ( void  )
protectedvirtual

Possibly overridden by the actual implementation, called after ending the garbage collection. As a default, do nothing.

Referenced by collectGarbage().

void elm::AbstractBlockAllocatorWithGC::free ( void *  block)

Function for compatibility with Allocator concept. Do nothing yet.

Parameters
blockBlock to free.
int elm::AbstractBlockAllocatorWithGC::freeCount ( void  ) const

References free_cnt.

Referenced by usedCount().

bool elm::AbstractBlockAllocatorWithGC::mark ( void *  ptr)
protected

Mark a block is living.

Parameters
ptrPointer on the block to mark.
Returns
True if the block was not already marked (continue shallow traversal), false else.

References elm::BitVector::bit(), elm::genstruct::Vector< T >::count(), and elm::BitVector::set().

Referenced by elm::BlockAllocatorWithGC< node_t >::mark().

int elm::AbstractBlockAllocatorWithGC::totalCount ( void  ) const

Compute the total count of allocated blocks (including used and fried ones).

Returns
Total count of allocated blocks.

References elm::genstruct::Vector< T >::length(), and elm::genstruct::Vector< T >::top().

Referenced by usedCount().

int elm::AbstractBlockAllocatorWithGC::usedCount ( void  ) const

Get the count of apparently used. This count is only precise just after a garbage collection. Else it may includes non-living blocks that have not been already collected.

Returns
In-use blocks.

References freeCount(), and totalCount().

Member Data Documentation

int elm::AbstractBlockAllocatorWithGC::free_cnt
protected

Referenced by allocate(), collectGarbage(), and freeCount().

free_t* elm::AbstractBlockAllocatorWithGC::free_list
protected

Referenced by allocate(), and collectGarbage().


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