diff options
author | Alexis211 <alexis211@gmail.com> | 2009-10-13 18:32:26 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-10-13 18:32:26 +0200 |
commit | 01665d725a200c3c51bcd834cc8324ec057286c4 (patch) | |
tree | a9ddc80b628c8b6226dbeab24d4c7de00dca7075 /Source/Kernel/MemoryManager/Heap.class.h | |
parent | 277d5fcb3b378089c0f3390a0b4d1b529075958a (diff) | |
download | Melon-01665d725a200c3c51bcd834cc8324ec057286c4.tar.gz Melon-01665d725a200c3c51bcd834cc8324ec057286c4.zip |
Heap is now in a separate class, Heap.
Diffstat (limited to 'Source/Kernel/MemoryManager/Heap.class.h')
-rw-r--r-- | Source/Kernel/MemoryManager/Heap.class.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Source/Kernel/MemoryManager/Heap.class.h b/Source/Kernel/MemoryManager/Heap.class.h new file mode 100644 index 0000000..a1feaa1 --- /dev/null +++ b/Source/Kernel/MemoryManager/Heap.class.h @@ -0,0 +1,61 @@ +#ifndef DEF_HEAP_CLASS_H +#define DEF_HEAP_CLASS_H + +#include <Core/common.wtf.h> + +//Heap minimum size : 2M +#define HEAP_MIN_SIZE 0x00200000 +//Heap magic number, for verifications +#define HEAP_MAGIC 0xBEEF1337 + +struct heap_header_t { + u32int magic; + bool is_hole; + u32int size; +}; + +struct heap_footer_t { + u32int magic; + heap_header_t *header; +}; + +struct heap_index_t { + heap_header_t **data; + u32int size; +}; + +class PageDirectory; + +class Heap { + private: + bool m_usable, m_user, m_rw; + u32int m_free, m_start, m_end; + heap_index_t m_index; + PageDirectory* m_pagedir; + + void insertIntoIndex(heap_header_t *e); + u32int findIndexEntry(heap_header_t *e); + void removeFromIndex(u32int idx); + void removeFromIndex(heap_header_t *e); + + void expand(u32int quantity); + void contract(); //Quantity is automatically calculated + + + public: + Heap(); + ~Heap(); + + bool usable() { return m_usable; } + + void create(u32int start, u32int size, u32int idxsize, PageDirectory* pagedir, bool user, bool rw); + + void* alloc(u32int sz, bool no_expand = false); + void free(void* ptr); + + u32int size() { return m_end - m_start; } + u32int free() { return m_free; } +}; + + +#endif |