![]() |
mutable
A Database System for Research and Fast Prototyping
|
This is the simplest kind of allocator. More...
#include <memory.hpp>
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_ |
| |
int | fd_ |
file descriptor of the underlying memory file | |
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.
|
inline |
Definition at line 147 of file memory.hpp.
|
inline |
Definition at line 148 of file memory.hpp.
|
overridevirtual |
Creates a new memory object with size
bytes of freshly allocated memory.
Implements m::memory::Allocator.
Definition at line 120 of file memory.cpp.
References allocations_, m::Ceil_To_Next_Page(), m::memory::Allocator::create_memory(), m::memory::Allocator::fd(), m::Is_Page_Aligned(), M_insist, m::memory::Allocator::Memory, and offset_.
Referenced by m::ColumnStore::ColumnStore(), m::PaxStore::PaxStore(), and m::RowStore::RowStore().
|
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().
|
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_.
|
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().
|
inline |
Returns the offset in the underlying memory file where the next allocation is placed.
Definition at line 153 of file memory.hpp.
|
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().
|
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().
|
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().