Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::vm::bounded_allocator Class Reference

#include <allocator.hpp>

Collaboration diagram for sysio::vm::bounded_allocator:

Public Member Functions

 bounded_allocator (size_t size)
 
template<typename T >
Talloc (size_t size=1)
 
template<typename T >
void reclaim (const T *ptr, size_t size=0)
 
void free ()
 
void reset ()
 
 bounded_allocator (size_t size)
 
template<typename T >
Talloc (size_t size=1)
 
template<typename T >
void reclaim (const T *ptr, size_t size=0)
 
void free ()
 
void reset ()
 

Public Attributes

size_t mem_size
 
std::unique_ptr< uint8_t[]> raw
 
size_t index = 0
 

Detailed Description

Definition at line 21 of file allocator.hpp.

Constructor & Destructor Documentation

◆ bounded_allocator() [1/2]

sysio::vm::bounded_allocator::bounded_allocator ( size_t size)
inline

Definition at line 23 of file allocator.hpp.

23 {
24 mem_size = size;
25 raw = std::unique_ptr<uint8_t[]>(new uint8_t[mem_size]);
26 }
std::unique_ptr< uint8_t[]> raw
Definition allocator.hpp:44
unsigned char uint8_t
Definition stdint.h:124

◆ bounded_allocator() [2/2]

sysio::vm::bounded_allocator::bounded_allocator ( size_t size)
inline

Definition at line 23 of file allocator.hpp.

23 {
24 mem_size = size;
25 raw = std::unique_ptr<uint8_t[]>(new uint8_t[mem_size]);
26 }

Member Function Documentation

◆ alloc() [1/2]

template<typename T >
T * sysio::vm::bounded_allocator::alloc ( size_t size = 1)
inline

Definition at line 28 of file allocator.hpp.

28 {
29 SYS_VM_ASSERT((sizeof(T) * size) + index <= mem_size, wasm_bad_alloc, "wasm failed to allocate native");
30 T* ret = (T*)(raw.get() + index);
31 index += sizeof(T) * size;
32 return ret;
33 }
#define T(meth, val, expected)
#define SYS_VM_ASSERT(expr, exc_type, msg)
Definition exceptions.hpp:8
CK_RV ret

◆ alloc() [2/2]

template<typename T >
T * sysio::vm::bounded_allocator::alloc ( size_t size = 1)
inline

Definition at line 28 of file allocator.hpp.

28 {
29 SYS_VM_ASSERT((sizeof(T) * size) + index <= mem_size, wasm_bad_alloc, "wasm failed to allocate native");
30 T* ret = (T*)(raw.get() + index);
31 index += sizeof(T) * size;
32 return ret;
33 }

◆ free() [1/2]

void sysio::vm::bounded_allocator::free ( )
inline

Definition at line 38 of file allocator.hpp.

38 {
39 SYS_VM_ASSERT(index > 0, wasm_double_free, "double free");
40 index = 0;
41 }

◆ free() [2/2]

void sysio::vm::bounded_allocator::free ( )
inline

Definition at line 38 of file allocator.hpp.

38 {
39 SYS_VM_ASSERT(index > 0, wasm_double_free, "double free");
40 index = 0;
41 }

◆ reclaim() [1/2]

template<typename T >
void sysio::vm::bounded_allocator::reclaim ( const T * ptr,
size_t size = 0 )
inline

Definition at line 36 of file allocator.hpp.

36{ /* noop for now */ }

◆ reclaim() [2/2]

template<typename T >
void sysio::vm::bounded_allocator::reclaim ( const T * ptr,
size_t size = 0 )
inline

Definition at line 36 of file allocator.hpp.

36{ /* noop for now */ }

◆ reset() [1/2]

void sysio::vm::bounded_allocator::reset ( )
inline

Definition at line 42 of file allocator.hpp.

42{ index = 0; }

◆ reset() [2/2]

void sysio::vm::bounded_allocator::reset ( )
inline

Definition at line 42 of file allocator.hpp.

42{ index = 0; }

Member Data Documentation

◆ index

size_t sysio::vm::bounded_allocator::index = 0

Definition at line 45 of file allocator.hpp.

◆ mem_size

size_t sysio::vm::bounded_allocator::mem_size

Definition at line 43 of file allocator.hpp.

◆ raw

std::unique_ptr< uint8_t[]> sysio::vm::bounded_allocator::raw

Definition at line 44 of file allocator.hpp.


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