CyberEngineMkIII
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CYBBlock.hpp
Go to the documentation of this file.
1 #pragma once
3 namespace CYB {
4  namespace Engine {
5  namespace Memory {
7  class Block {
8  protected:
9  enum : unsigned long long {
10  MAGIC_HEADER = 0x0123456789ABCDEF,
11  MAGIC_FOOTER = 0xFEDCBA9876543210,
12  };
13 
14 #ifdef DEBUG //Block debug headers
15  private:
16  unsigned long long FMagicHeader;
17 #endif
18  public:
20  private:
21  unsigned int FSizeAndFreeBit,
23 #ifdef DEBUG
24  unsigned long long FMagicFooter;
25 #endif
26  private:
35  static unsigned int InitializeData(const unsigned int ASize, const bool AFree) noexcept; // <- It's an unsigned int for a reason dude
36 
44  unsigned int CalculateOffset(const Block& ABlock) noexcept;
45  public:
53  static Block& FromData(void* const AData);
62  Block(const unsigned int ASpaceAvailable, const Block& ALeftBlock, const bool AFree) noexcept;
64  Block(const Block&) = delete;
71  void* GetData(void) noexcept;
72 
79  Block& RightBlock(void) noexcept;
86  const Block& RightBlock(void) const noexcept;
93  Block* LeftBlock(void) noexcept;
94 
101  void SetSize(const unsigned int ANewSize) noexcept;
108  void SetFree(const bool ANewFree) noexcept;
109 
116  bool IsFree(void) const noexcept;
123  unsigned int Size(void) const noexcept;
124 
131  bool IsLargeBlock(void) const noexcept;
132 
138  void Validate(void) const;
139 
147  Block& Splice(const unsigned int ASizeToKeep) noexcept;
148 
155  Block& EatLeftBlock(void) noexcept;
156  };
157  };
158  };
159 };
bool IsFree(void) const noexcept
Check if this Block is free.
Definition: CYBBlock.cpp:47
Block & EatLeftBlock(void) noexcept
Merge size and header into the size of the Block to the left. Does not modify free lists...
Definition: CYBBlock.cpp:109
Block & RightBlock(void) noexcept
Get the block to the right of this Block.
Definition: CYBBlock.cpp:71
Block(const unsigned int ASpaceAvailable, const Block &ALeftBlock, const bool AFree) noexcept
Create a Block. Should be used with operator new in a memory location at least ASpaceAvailable large...
Definition: CYBBlock.cpp:12
void SetFree(const bool ANewFree) noexcept
Set the Block's free state.
Definition: CYBBlock.cpp:84
Block & Splice(const unsigned int ASizeToKeep) noexcept
Separate this block into two.
Definition: CYBBlock.cpp:98
void * GetData(void) noexcept
Get the data portion of the memory owned by this Block.
Definition: CYBBlock.cpp:55
static unsigned int InitializeData(const unsigned int ASize, const bool AFree) noexcept
Returns the Size and Free integer given a size and free state.
Definition: CYBBlock.cpp:25
void SetSize(const unsigned int ANewSize) noexcept
Set the Block's size.
Definition: CYBBlock.cpp:80
static Block & FromData(void *const AData)
Retrieves a reference to a Block given it's data pointer.
Definition: CYBBlock.cpp:59
bool IsLargeBlock(void) const noexcept
Check if this Block is a LargeBlock.
Definition: CYBBlock.cpp:51
unsigned int CalculateOffset(const Block &ABlock) noexcept
Calculate the byte offset to another Block.
Definition: CYBBlock.cpp:34
unsigned int FOffsetToPreviousBlock
The offset from the block behind it.
Definition: CYBBlock.hpp:21
void Validate(void) const
Checks the validity of a Block HCFs if invalid. Has no effect outside of DEBUG mode.
Definition: CYBBlock.cpp:91
Block * LeftBlock(void) noexcept
Get the block to the left of this Block.
Definition: CYBBlock.cpp:65
A unit of memory allocation.
Definition: CYBBlock.hpp:7
unsigned int Size(void) const noexcept
Get the size of the Block.
Definition: CYBBlock.cpp:41
unsigned int FSizeAndFreeBit
The size of this block and it's free bit.
Definition: CYBBlock.hpp:21
Block * FNextFree
The next block in the free list.
Definition: CYBBlock.hpp:19