mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
m::memory::LinearAllocator Struct Reference

This is the simplest kind of allocator. More...

#include <memory.hpp>

Inheritance diagram for m::memory::LinearAllocator:
[legend]
Collaboration diagram for m::memory::LinearAllocator:
[legend]

Public Member Functions

 LinearAllocator ()
 
 ~LinearAllocator ()
 
Memory allocate (std::size_t size) override
 Creates a new memory object with size bytes of freshly allocated memory.
 
std::size_t offset () const
 Returns the offset in the underlying memory file where the next allocation is placed.
 
int fd () const
 Return the file descriptor of the underlying memory file.
 

Protected Member Functions

Memory create_memory (void *addr, std::size_t size, std::size_t offset)
 Helper method to inherit the friend ability to construct a Memory object.
 

Private Member Functions

void deallocate (Memory &&mem) override
 Deallocates a memory object.
 

Private Attributes

std::size_t offset_ = 0
 the offset from the start of the memory file of the next allocation
 
std::vector< std::size_t > allocations_
 

‍stack of allocations; allocations can be marked deallocated for later reclaiming


 
int fd_
 file descriptor of the underlying memory file
 

Detailed Description

This is the simplest kind of allocator.

The idea is to keep a pointer at the first memory address of your memory chunk and move it every time an allocation is done. In this allocator, the internal fragmentation is kept to a minimum because all elements are sequentially inserted and the only fragmentation between them is the alignment. Note that allocations are always page aligned and whole multiples of an entire page. There is no overhead to allocation and existing allocations are never modified. Deallocation can only reclaim memory if all chronologically later allocations have been deallocated before. If possible, deallocate memory in the inverse order of allocation.

Definition at line 138 of file memory.hpp.

Constructor & Destructor Documentation

◆ LinearAllocator()

m::memory::LinearAllocator::LinearAllocator ( )
inline

Definition at line 147 of file memory.hpp.

◆ ~LinearAllocator()

m::memory::LinearAllocator::~LinearAllocator ( )
inline

Definition at line 148 of file memory.hpp.

Member Function Documentation

◆ allocate()

M_LCOV_EXCL_STOP Memory LinearAllocator::allocate ( std::size_t  size)
overridevirtual

◆ create_memory()

Memory Allocator::create_memory ( void *  addr,
std::size_t  size,
std::size_t  offset 
)
protectedinherited

Helper method to inherit the friend ability to construct a Memory object.

Definition at line 50 of file memory.cpp.

References m::memory::Allocator::Memory.

Referenced by allocate().

◆ deallocate()

void LinearAllocator::deallocate ( Memory &&  mem)
overrideprivatevirtual

Deallocates a memory object.

Implements m::memory::Allocator.

Definition at line 162 of file memory.cpp.

References allocations_, m::and, m::memory::Allocator::fd(), M_insist, and offset_.

◆ fd()

int m::memory::Allocator::fd ( ) const
inlineinherited

Return the file descriptor of the underlying memory file.

Definition at line 29 of file memory.hpp.

Referenced by allocate(), deallocate(), and m::memory::Memory::dump().

◆ offset()

std::size_t m::memory::LinearAllocator::offset ( ) const
inline

Returns the offset in the underlying memory file where the next allocation is placed.

Definition at line 153 of file memory.hpp.

Field Documentation

◆ allocations_

std::vector<std::size_t> m::memory::LinearAllocator::allocations_
private

‍stack of allocations; allocations can be marked deallocated for later reclaiming

Definition at line 144 of file memory.hpp.

Referenced by allocate(), and deallocate().

◆ fd_

int m::memory::Allocator::fd_
privateinherited

file descriptor of the underlying memory file

Definition at line 22 of file memory.hpp.

Referenced by m::memory::Allocator::Allocator(), and m::memory::Allocator::~Allocator().

◆ offset_

std::size_t m::memory::LinearAllocator::offset_ = 0
private

the offset from the start of the memory file of the next allocation

Definition at line 141 of file memory.hpp.

Referenced by allocate(), and deallocate().


The documentation for this struct was generated from the following files: