Kagome
Polkadot Runtime Engine in C++17
kagome::runtime::MemoryAllocator Class Referencefinal

#include <memory_allocator.hpp>

Collaboration diagram for kagome::runtime::MemoryAllocator:

Classes

struct  MemoryHandle
 

Public Member Functions

 MemoryAllocator (MemoryHandle memory, size_t size, WasmPointer heap_base)
 
WasmPointer allocate (WasmSize size)
 
std::optional< WasmSizedeallocate (WasmPointer ptr)
 
template<typename T >
bool checkAddress (WasmPointer addr) noexcept
 
bool checkAddress (WasmPointer addr, size_t size) noexcept
 
std::optional< WasmSizegetDeallocatedChunkSize (WasmPointer ptr) const
 following methods are needed mostly for testing purposes More...
 
std::optional< WasmSizegetAllocatedChunkSize (WasmPointer ptr) const
 
size_t getAllocatedChunksNum () const
 
size_t getDeallocatedChunksNum () const
 

Private Member Functions

WasmPointer freealloc (WasmSize size)
 
WasmPointer growAlloc (WasmSize size)
 
void resize (WasmSize size)
 

Private Attributes

MemoryHandle memory_
 
std::unordered_map< WasmPointer, WasmSizeallocated_
 
std::map< WasmPointer, WasmSizedeallocated_
 
size_t offset_
 
size_t size_
 
log::Logger logger_
 

Detailed Description

Implementation of allocator for the runtime memory Combination of monotonic and free-list allocator

Definition at line 45 of file memory_allocator.hpp.


Class Documentation

struct kagome::runtime::MemoryAllocator::MemoryHandle

Definition at line 47 of file memory_allocator.hpp.

Collaboration diagram for kagome::runtime::MemoryAllocator::MemoryHandle:
Class Members
function< size_t()> getSize
function< void(size_t)> resize

Constructor & Destructor Documentation

kagome::runtime::MemoryAllocator::MemoryAllocator ( MemoryHandle  memory,
size_t  size,
WasmPointer  heap_base 
)

Definition at line 18 of file memory_allocator.cpp.

Member Function Documentation

WasmPointer kagome::runtime::MemoryAllocator::allocate ( WasmSize  size)

Definition at line 36 of file memory_allocator.cpp.

template<typename T >
bool kagome::runtime::MemoryAllocator::checkAddress ( WasmPointer  addr)
inlinenoexcept

Definition at line 57 of file memory_allocator.hpp.

bool kagome::runtime::MemoryAllocator::checkAddress ( WasmPointer  addr,
size_t  size 
)
inlinenoexcept

Definition at line 61 of file memory_allocator.hpp.

std::optional< WasmSize > kagome::runtime::MemoryAllocator::deallocate ( WasmPointer  ptr)

Definition at line 67 of file memory_allocator.cpp.

WasmPointer kagome::runtime::MemoryAllocator::freealloc ( WasmSize  size)
private

Finds memory segment of given size among deallocated pieces of memory and allocates a memory there

Parameters
sizeof target memory
Returns
address of memory of given size, or -1 if it is impossible to allocate this amount of memory

Definition at line 108 of file memory_allocator.cpp.

std::optional< WasmSize > kagome::runtime::MemoryAllocator::getAllocatedChunkSize ( WasmPointer  ptr) const

Definition at line 193 of file memory_allocator.cpp.

size_t kagome::runtime::MemoryAllocator::getAllocatedChunksNum ( ) const

Definition at line 200 of file memory_allocator.cpp.

std::optional< WasmSize > kagome::runtime::MemoryAllocator::getDeallocatedChunkSize ( WasmPointer  ptr) const

following methods are needed mostly for testing purposes

Definition at line 186 of file memory_allocator.cpp.

size_t kagome::runtime::MemoryAllocator::getDeallocatedChunksNum ( ) const

Definition at line 204 of file memory_allocator.cpp.

WasmPointer kagome::runtime::MemoryAllocator::growAlloc ( WasmSize  size)
private

Resize memory and allocate memory segment of given size

Parameters
sizememory size to be allocated
Returns
pointer to the allocated memory 0 if it is impossible to allocate this amount of memory

Definition at line 153 of file memory_allocator.cpp.

void kagome::runtime::MemoryAllocator::resize ( WasmSize  size)
private

We use this condition to avoid deallocated_ pointers fixup

Definition at line 175 of file memory_allocator.cpp.

Member Data Documentation

std::unordered_map<WasmPointer, WasmSize> kagome::runtime::MemoryAllocator::allocated_
private

Definition at line 95 of file memory_allocator.hpp.

std::map<WasmPointer, WasmSize> kagome::runtime::MemoryAllocator::deallocated_
private

Definition at line 98 of file memory_allocator.hpp.

log::Logger kagome::runtime::MemoryAllocator::logger_
private

Definition at line 105 of file memory_allocator.hpp.

MemoryHandle kagome::runtime::MemoryAllocator::memory_
private

Definition at line 92 of file memory_allocator.hpp.

size_t kagome::runtime::MemoryAllocator::offset_
private

Definition at line 101 of file memory_allocator.hpp.

size_t kagome::runtime::MemoryAllocator::size_
private

Definition at line 103 of file memory_allocator.hpp.


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