로딩중...
검색중...
일치하는것 없음
by::chunk 클래스 참조

Memory chunk for block-based allocation 더 자세히 ...

#include <chunk.hpp>

by::chunk에 대한 상속 다이어그램 :
by::allocator by::memoryHaver by::watcher

Public 멤버 함수

 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.
 
- by::allocator(으)로부터 상속된 Public 멤버 함수
 allocator (ncnt blksize=1)
 
ncnt getBlkSize () const
 
- by::memoryHaver(으)로부터 상속된 Public 멤버 함수
nbool has (const instance *it) const BY_SIDE_FUNC(has)
 
nbool isFull () const
 
nbool isCapable () const
 

정적 Public 속성

static constexpr ncnt MIN_SZ = 20
 

Protected 멤버 함수

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.

Remarks
Fixed memory size chunk has a _resize() function for flexible memory growth, but following memlite's concept, this is not exposed publicly. Consequently, chunk memory is fixed at object creation. If additional memory is needed, create and operate more chunk objects.

Block size

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:

new chunk(sizeof(int64), 100)
Memory chunk for block-based allocation
Definition chunk.hpp:57
Rich logging support with polymorphic type conversion
Definition richLog.hpp:34

Real block size

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.

ArrayList implementation

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. On array initialization with size, place integer value n+1 before the bytes occupied by nth element. Example: size=4 results in [1, 2, 3, 4]
  2. _head represents index of most recently added element, initialized to 0. _heap points to heap-allocated memory.
  3. When external new1 requests memory allocation, _head is assigned the int value at current _head-th element. Example: first new1() assigns _head the value 1 from _heap[0], meaning next new1() treats _heap[1] as available empty element.
  4. Return address of allocated memory for just-retrieved element. _head = 1, [in-use, 2, 3, 4]
  5. On memory release, receive memory address to release as void* parameter. Example: del(used = _heap[0])
  6. Assign _head value to that memory (assuming destructor already called). *used = _head // [1, 2, 3, 4]
  7. Assign _head to index of currently releasing memory. Calculate index via pointer arithmetic for _heap distance from _head. _head = _heap - used // _heap - _heap --> 0 _head = 0, [1, 2, 3, 4]

멤버 함수 문서화

◆ _get()

void * by::chunk::_get ( nidx n)
overrideprotectedvirtual
반환값
returns regarding current size, not length. can return garbage if size is bigger than n.

by::memoryHaver를 구현.

◆ del()

nbool by::chunk::del ( void * used,
ncnt  )
overridevirtual

by::allocator를 구현.

by::watcher에서 재구현되었습니다.

◆ has()

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

Checks if this chunk contains the memory allocated for the given instance.

매개변수
itThe instance whose memory location is to be checked.
반환값
true if the instance's memory is within this chunk, false otherwise.

by::memoryHaver를 구현.

◆ len()

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

by::memoryHaver를 구현.

◆ new1()

void * by::chunk::new1 ( )
overridevirtual

by::allocator를 구현.

◆ rel()

nbool by::chunk::rel ( )
overridevirtual

by::memoryHaver를 구현.

◆ size()

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

by::memoryHaver를 구현.


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: