Loading...
Searching...
No Matches
by::chunks Class Reference

Collection of memory chunks for scalable allocation. More...

#include <chunks.hpp>

Inheritance diagram for by::chunks:
by::allocator by::memoryHaver

Public Member Functions

 chunks (ncnt blkbyte=0)
 
chunkoperator[] (nidx n)
 
const chunkoperator[] (nidx n) const BY_CONST_FUNC(operator[](n))
 
chunkoperator[] (const instance &it)
 
const chunkoperator[] (const instance &it) const BY_CONST_FUNC(operator[](it))
 
chunkget (nidx n)
 
chunkget (const instance &it)
 
chunkget (const instance *it) BY_SIDE_FUNC(get)
 
const chunkget (nidx n) const BY_CONST_FUNC(get(n)) const chunk *get(const instance &it) const BY_CONST_FUNC(get(it)) const chunk *get(const instance *it) const BY_CONST_FUNC(get(it)) void *new 1() override
 
nbool del (void *pt, ncnt sz) override
 
virtual nbool resize (ncnt new1)
 
nbool has (const instance &it) const override
 Checks if any of the managed chunks contain the memory allocated for the given instance.
 
ncnt len () const override
 
ncnt size () const override
 
nbool rel () override
 
- Public Member Functions inherited from by::allocator
 allocator (ncnt blksize=1)
 
virtual voidnew1 ()=0
 
ncnt getBlkSize () const
 
- Public Member Functions inherited from by::memoryHaver
nbool has (const instance *it) const BY_SIDE_FUNC(has)
 
nbool isFull () const
 
nbool isCapable () const
 

Additional Inherited Members

Detailed Description

Collection of memory chunks for scalable allocation.

Manages multiple chunk instances. Since chunk uses only fixed-size memory created at initialization, chunks adds/removes multiple chunks to manage memory dynamically.

chunks also provides only fixed memory

Since chunks adds or removes chunks, and each chunk cell uses only fixed size, chunks can also only allocate fixed-size memory.

Coordination with pool

The first to receive memory requests is pool class. When pool receives a memory size to allocate, it lazily retrieves a chunks instance capable of handling that memory size and requests new1(). chunks::new1() finds a chunk capable of allocating memory, and if none exists, creates an additional chunk.

Available chunk search algorithm

The most recently memory-allocated chunk has the highest probability of being able to allocate additionally. Member variable _s holds the index of the most recently allocated chunk. If _chunks[_s] has no available memory, increment _s. Like a circular array, _chunks' end connects to its beginning. If _s loops back to its pre-traversal value and still no available memory exists, the entire chunks has no available memory, so enters resize().

Remarks
Cannot use vector Obviously, vector is managed on heap, so shouldn't use vector while making a custom memory pool. Planned for future modification.

Member Function Documentation

◆ del()

nbool by::chunks::del ( void * pt,
ncnt sz )
overridevirtual

Implements by::allocator.

◆ has()

nbool by::chunks::has ( const instance & it) const
overridevirtual

Checks if any of the managed chunks contain the memory allocated for the given instance.

Parameters
itThe instance whose memory location is to be checked.
Returns
true if the instance's memory is within any of this chunks' child chunks, false otherwise.

Implements by::memoryHaver.

◆ len()

ncnt by::chunks::len ( ) const
overridevirtual

Implements by::memoryHaver.

◆ rel()

nbool by::chunks::rel ( )
overridevirtual

Implements by::memoryHaver.

◆ resize()

virtual nbool by::chunks::resize ( ncnt new1)
virtual
Remarks
chunk can resize its data. but can't persist whole memory allocated before, it's a kind of memory flashing and can't give a way for accessing it. at outside, ptr for them should be daggled.

◆ size()

ncnt by::chunks::size ( ) const
overridevirtual

Implements by::memoryHaver.


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