Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
AbstractBlockAllocatorWithGC Class Referenceabstract

#include <elm/alloc/BlockAllocatorWithGC.h>

+ Inheritance diagram for AbstractBlockAllocatorWithGC:

Classes

struct  free_t
 

Public Member Functions

 AbstractBlockAllocatorWithGC (t::size block_size, t::size chunk_size=1<< 20)
 
virtual ~AbstractBlockAllocatorWithGC (void)
 
voidallocate (void)
 
bool needsCollect () const
 
bool isSync ()
 
void setSync ()
 
void setAsync ()
 
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
 
voidallocate (t::size size)
 
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)
 
virtual void destroy (void *p)
 

Protected Attributes

free_tfree_list
 
int free_cnt
 

Detailed Description

Implements the block allocator whose template form is BlockAllocatorWithGC.

Member Typedef Documentation

◆ free_t

Constructor & Destructor Documentation

◆ 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 Vector< T, E, A >::add(), elm::max(), and Vector< T, E, A >::top().

◆ ~AbstractBlockAllocatorWithGC()

Member Function Documentation

◆ allocate() [1/2]

void * allocate ( t::size  size)

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.

References AbstractBlockAllocatorWithGC::allocate().

◆ allocate() [2/2]

◆ beginGC()

void beginGC ( void  )
protectedvirtual

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

Referenced by AbstractBlockAllocatorWithGC::collectGarbage().

◆ blockSize()

t::size blockSize ( void  ) const
inline

Get the block size.

Returns
Block size (in bytes).

◆ chunkSize()

t::size chunkSize ( void  ) const
inline

Get the memory chunk size.

Returns
Memory chunk size (in bytes).

◆ collect()

void 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 AbstractBlockAllocatorWithGC::collectGarbage().

◆ collectGarbage()

◆ destroy()

void destroy ( void p)
protectedvirtual

This function is called each time a block is released to the free list to let user perform some cleanup.

Parameters
pPointer to the block.

Reimplemented in BlockAllocatorWithGC< T >, and BlockAllocatorWithGC< node_t >.

Referenced by AbstractBlockAllocatorWithGC::collectGarbage().

◆ endGC()

void endGC ( void  )
protectedvirtual

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

Referenced by AbstractBlockAllocatorWithGC::collectGarbage().

◆ free()

void free ( void block)

Function for compatibility with Allocator concept. Do nothing yet.

Parameters
blockBlock to free.

◆ freeCount()

int freeCount ( void  ) const
inline

◆ isSync()

bool isSync ( )
inline

Test if the allocator is synchronous or not.

Returns
True if synchronous, false else.

◆ mark()

bool 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 BitVector::bit(), Vector< T, E, A >::count(), and BitVector::set().

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

◆ needsCollect()

bool needsCollect ( ) const
inline

Test if garbage collection is required (in synchronous model).

Returns
True if garbage collection is needed, false else.

◆ setAsync()

void setAsync ( )
inline

void AbstractBlockAllocatorWithGC::setSync(); Set the allocator synchronous.

Set the allocator asynchronous.

References Flags< T >::clear().

◆ setSync()

void setSync ( )
inline

References Flags< T >::set().

◆ totalCount()

int totalCount ( void  ) const

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

Returns
Total count of allocated blocks.

References Vector< T, E, A >::length(), and Vector< T, E, A >::top().

Referenced by AbstractBlockAllocatorWithGC::collectGarbage(), and AbstractBlockAllocatorWithGC::usedCount().

◆ usedCount()

int usedCount ( void  ) const
inline

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 AbstractBlockAllocatorWithGC::freeCount(), and AbstractBlockAllocatorWithGC::totalCount().

Member Data Documentation

◆ free_cnt

◆ free_list


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