Max OS 0.3
Loading...
Searching...
No Matches
slab.h
1//
2// Created by 98max on 8/07/2026.
3//
4
5#ifndef MAXOS_MEMORY_ALLOCATOR_SLAB_H
6#define MAXOS_MEMORY_ALLOCATOR_SLAB_H
7
8#include <cstddef>
9#include <cstdint>
10
11namespace MaxOS::memory::allocator {
12
17 typedef struct SlabHeader {
18 SlabHeader* next;
19 void* page;
20
21 uint32_t used_blocks;
22 uint32_t total_blocks;
23
24 uint64_t block_state[4];
25
27
32 class SlabCache {
33
34 private:
35
36 size_t m_slab_size;
37
38 slab_header_t* m_root_slab = nullptr;
39 slab_header_t* new_slab();
40
41
42 public:
43 SlabCache(size_t size);
44 ~SlabCache();
45
46 void* allocate_slab();
47 void free_slav(void* address);
48
49
50 };
51
57
58 private:
59
61 SlabCache m_caches[8];
62 SlabCache* get_cache(size_t size);
63
64 virtual void* expand_heap(size_t size);
65 virtual void* allocate_extra_space(size_t requested_size, size_t& actual_size);
66
67 public:
69 virtual ~SlabAllocator();
70
71 virtual void setup_region(uintptr_t address, size_t length);
72
73 virtual void* allocate(size_t size);
74 virtual void unallocate(void* pointer);
75
76 virtual size_t amount_used();
77 virtual size_t align(size_t size);
78
79 };
80
81}
82
83#endif //MAXOS_MEMORY_ALLOCATOR_SLAB_H
Memory allocator that handles fixed sized chunks of data.
Definition slab.h:56
Slab handler for a given size.
Definition slab.h:32
Metadata for a slab in the slab allocator.
Definition slab.h:17