Memory chunk for block-based allocation. More...
#include <chunk.hpp>
Public Member Functions | |
| chunk (ncnt blockSz=1, ncnt sz=MIN_SZ) | |
| void * | operator[] (nidx n) |
| const void * | operator[] (nidx n) const BY_CONST_FUNC(operator[](n)) |
| void * | get (nidx n) |
| void * | new1 () override |
| nbool | del (void *used, ncnt) override |
| ncnt | len () const override |
| ncnt | size () const override |
| nbool | rel () override |
| nbool | has (const instance &it) const override |
| Checks if this chunk contains the memory allocated for the given instance. | |
Public Member Functions inherited from by::allocator | |
| allocator (ncnt blksize=1) | |
| 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 |
Static Public Attributes | |
| static constexpr ncnt | MIN_SZ = 20 |
Protected Member Functions | |
| void * | _get (nidx n) override |
| nuchar * | _getHeap () |
| const nuchar * | _getHeap () const BY_CONST_FUNC(_getHeap()) nbool _resize(ncnt new Sz) |
Memory chunk for block-based allocation.
The minimum unit class that can actually allocate memory in memlite. All memory management is performed by linking chunks together.
chunk receives blockSize and size at creation. blockSize is the minimum unit size one instance occupies in memory. size defines how many such instances can fit. For example, to create a chunk holding 100 int64 values:
Actual memory allocation uses real block size instead of block size for optimization. Rather than allocating in small 1 or 2 byte units during CPU operations, it's more efficient to allocate minimum bytes appropriate for the CPU level, like 4 or 8 bytes.
chunk is implemented as an ArrayList. Size is fixed, but addition and deletion are free within size limits, with very fast random access.
Algorithm: 0. Precondition: Each element's byte size must be >= 4. All elements have identical byte sizes. Since chunk handles everything as void*, elements without values are treated as int type.
1 from _heap[0], meaning next new1() treats _heap[1] as available empty element.Implements by::memoryHaver.
Implements by::allocator.
Reimplemented in by::watcher.
Checks if this chunk contains the memory allocated for the given instance.
| it | The instance whose memory location is to be checked. |
Implements by::memoryHaver.
|
overridevirtual |
Implements by::memoryHaver.
|
overridevirtual |
Implements by::allocator.
|
overridevirtual |
Implements by::memoryHaver.
|
overridevirtual |
Implements by::memoryHaver.