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

Memory watcher for tracking instance lifecycle and allocation. More...

#include <watcher.hpp>

Inheritance diagram for by::watcher:
by::chunk by::allocator by::memoryHaver

Public Member Functions

lifeoperator[] (nidx n)
 
const lifeoperator[] (nidx n) const BY_CONST_FUNC(operator[](n))
 
lifeoperator[] (id id)
 
const lifeoperator[] (id id) const BY_CONST_FUNC(operator[](id))
 
lifeget (nidx n)
 
lifeget (id newId)
 
const lifeget (nidx n) const BY_CONST_FUNC(get(n)) const life *get(id new Id) const BY_CONST_FUNC(get(newId)) void *new 1() override
 Allocates new life object from pre-allocated chunk.
 
nbool del (void *used, ncnt sz) override
 Returns life object back to available pool.
 
- Public Member Functions inherited from by::chunk
 chunk (ncnt blockSz=1, ncnt sz=MIN_SZ)
 
voidoperator[] (nidx n)
 
const voidoperator[] (nidx n) const BY_CONST_FUNC(operator[](n))
 
voidget (nidx n)
 
voidnew1 () 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
 

Protected Member Functions

id _genId (void *pt) const
 Generates unique id for instance pointer.
 
nidx _getIdx (void *it) const
 Calculates index in chunk from pointer address.
 
- Protected Member Functions inherited from by::chunk
void_get (nidx n) override
 
nuchar_getHeap ()
 
const nuchar_getHeap () const BY_CONST_FUNC(_getHeap()) nbool _resize(ncnt new Sz)
 

Additional Inherited Members

- Static Public Attributes inherited from by::chunk
static constexpr ncnt MIN_SZ = 20
 

Detailed Description

Memory watcher for tracking instance lifecycle and allocation.

One pillar of memory management that manages created object lifecycles. Whenever an instance is created, watcher additionally allocates a life object and uses reference counting to determine object destruction timing.

Reference counting

When binder binds an instance, life increments its strong count by 1. When binder calls rel() on instance, decrements count by 1. At 0, deletes from memory. instance uses operator delete() to make instancer execute memory release work.

Member Function Documentation

◆ _genId()

id by::watcher::_genId ( void * pt) const
protected

Generates unique id for instance pointer.

Returns
Generated id combining pointer address information
Note
Used internally to create ids for newly allocated instances

◆ _getIdx()

nidx by::watcher::_getIdx ( void * it) const
protected

Calculates index in chunk from pointer address.

Returns
Index position of object within chunk
Note
Helper for mapping pointers back to chunk indices

◆ del()

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

Returns life object back to available pool.

Returns
true on success, false on failure
Note
Overrides chunk::del() to reclaim life objects for reuse

Reimplemented from by::chunk.

◆ get()

const life * by::watcher::get ( nidx n) const
overridenew

Allocates new life object from pre-allocated chunk.

Returns
Pointer to available life object, or nullptr if chunk full
Note
Overrides chunk::new1() to provide life objects for instance tracking

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