|
Kagome
Polkadot Runtime Engine in C++17
|
#include <memory_allocator.hpp>
Classes | |
| struct | MemoryHandle |
Public Member Functions | |
| MemoryAllocator (MemoryHandle memory, size_t size, WasmPointer heap_base) | |
| WasmPointer | allocate (WasmSize size) |
| std::optional< WasmSize > | deallocate (WasmPointer ptr) |
| template<typename T > | |
| bool | checkAddress (WasmPointer addr) noexcept |
| bool | checkAddress (WasmPointer addr, size_t size) noexcept |
| std::optional< WasmSize > | getDeallocatedChunkSize (WasmPointer ptr) const |
| following methods are needed mostly for testing purposes More... | |
| std::optional< WasmSize > | getAllocatedChunkSize (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, WasmSize > | allocated_ |
| std::map< WasmPointer, WasmSize > | deallocated_ |
| size_t | offset_ |
| size_t | size_ |
| log::Logger | logger_ |
Implementation of allocator for the runtime memory Combination of monotonic and free-list allocator
Definition at line 45 of file memory_allocator.hpp.
| struct kagome::runtime::MemoryAllocator::MemoryHandle |
Definition at line 47 of file memory_allocator.hpp.
| Class Members | ||
|---|---|---|
| function< size_t()> | getSize | |
| function< void(size_t)> | resize | |
| kagome::runtime::MemoryAllocator::MemoryAllocator | ( | MemoryHandle | memory, |
| size_t | size, | ||
| WasmPointer | heap_base | ||
| ) |
Definition at line 18 of file memory_allocator.cpp.
| WasmPointer kagome::runtime::MemoryAllocator::allocate | ( | WasmSize | size | ) |
Definition at line 36 of file memory_allocator.cpp.
|
inlinenoexcept |
Definition at line 57 of file memory_allocator.hpp.
|
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.
|
private |
Finds memory segment of given size among deallocated pieces of memory and allocates a memory there
| size | of target 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.
|
private |
Resize memory and allocate memory segment of given size
| size | memory size to be allocated |
Definition at line 153 of file memory_allocator.cpp.
|
private |
We use this condition to avoid deallocated_ pointers fixup
Definition at line 175 of file memory_allocator.cpp.
|
private |
Definition at line 95 of file memory_allocator.hpp.
|
private |
Definition at line 98 of file memory_allocator.hpp.
|
private |
Definition at line 105 of file memory_allocator.hpp.
|
private |
Definition at line 92 of file memory_allocator.hpp.
|
private |
Definition at line 101 of file memory_allocator.hpp.
|
private |
Definition at line 103 of file memory_allocator.hpp.