HAllocator
A Simple C++ Memory Allocator
Loading...
Searching...
No Matches
Classes | Namespaces | Macros
Block.hpp File Reference

Memory block management with Red-Black tree based allocator. More...

#include <sys/mman.h>
#include <algorithm>
#include <cstddef>
#include <fstream>
#include "RBTreeDriver.hpp"
Include dependency graph for Block.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  hh::halloc::MemoryNode
 Node structure for both Red-Black tree and doubly-linked list. More...
 
class  hh::halloc::Block
 Manages a contiguous memory block with RB-tree based allocation. More...
 

Namespaces

namespace  hh
 
namespace  hh::halloc
 

Macros

#define REQUEST_MEMORY_VIA_MMAP(size)    mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)
 Allocates memory from the operating system using mmap.
 
#define RELEASE_MEMORY_VIA_MUNMAP(ptr, size)   munmap(ptr, size)
 Releases memory back to the operating system using munmap.
 
#define MEMORY_NODE_SIZE   sizeof(MemoryNode)
 Size of the MemoryNode metadata structure.
 

Detailed Description

Memory block management with Red-Black tree based allocator.

This file implements a memory block that uses a Red-Black tree to track free memory regions and provides efficient allocation/deallocation.

Macro Definition Documentation

◆ MEMORY_NODE_SIZE

#define MEMORY_NODE_SIZE   sizeof(MemoryNode)

Size of the MemoryNode metadata structure.

◆ RELEASE_MEMORY_VIA_MUNMAP

#define RELEASE_MEMORY_VIA_MUNMAP (   ptr,
  size 
)    munmap(ptr, size)

Releases memory back to the operating system using munmap.

Parameters
ptrPointer to memory to release
sizeSize in bytes to release

◆ REQUEST_MEMORY_VIA_MMAP

#define REQUEST_MEMORY_VIA_MMAP (   size)     mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)

Allocates memory from the operating system using mmap.

Parameters
sizeSize in bytes to allocate
Returns
Pointer to allocated memory or MAP_FAILED on error