chunk.hpp
Go to the documentation of this file.
1
2#pragma once
3
5
6namespace by {
7
12 class _nout chunk: public allocator {
13 BY_ME(chunk, allocator)
14 BY_INIT_META(me)
15 friend class watcher;
16
17 public:
18 // chunk:
19 static constexpr ncnt MIN_SZ = 20;
20
21 public:
22 explicit chunk(ncnt blockSz = 1, ncnt sz = MIN_SZ);
23 ~chunk();
24
25 public:
26 void* operator[](nidx n);
27 const void* operator[](nidx n) const BY_CONST_FUNC(operator[](n));
28
29 public:
30 void* get(nidx n) { return _get(n); }
31
32 // allocator:
33 void* new1() override;
34 nbool del(void* used, ncnt) override;
35 // MemoryHaver:
36 ncnt len() const override;
37 ncnt size() const override;
38 nbool rel() override;
39
40 using super::has;
41 nbool has(const instance& it) const override;
42
43 protected:
44 // MemoryHaver:
47 void* _get(nidx n) override;
48 nuchar* _getHeap();
49 const nuchar* _getHeap() const BY_CONST_FUNC(_getHeap())
50 nbool _resize(ncnt newSz);
51
52 private:
53 // chunk:
54 const nuchar* _getEOB() const BY_CONST_FUNC(_getEOB())
55 nuchar* _getEOB();
56 nbool _index(nidx start);
57 ncnt _getRealBlkSize();
58 void* _allocHeap(ncnt new_sz);
59 nbool _freeHeap(nuchar** heap);
60
61 nidx _head;
62 ncnt _len, _sz;
63 nuchar* _heap;
64 };
65} // namespace by
Abstract allocator interface for memory management.
Definition: allocator.hpp:12
Memory chunk for block-based allocation.
Definition: chunk.hpp:12
void * _get(nidx n) override
Base class for all managed instances in memlite system.
Definition: instance.hpp:20
Memory watcher for tracking instance lifecycle and allocation.
Definition: watcher.hpp:13