mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Private Member Functions | Private Attributes
LinearAllocator Struct Reference

A simple linear allocator which keeps a global pointer to the next free memory address and advances it for allocation. More...

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

Public Member Functions

 LinearAllocator (const memory::AddressSpace &memory, uint32_t start_addr)
 
 ~LinearAllocator ()
 
void * raw_allocate (uint32_t bytes, uint32_t alignment) override
 Pre-allocates memory for bytes consecutive bytes with alignment requirement align and returns a raw pointer to the beginning of this memory.
 
Ptr< void > pre_allocate (uint32_t bytes, uint32_t alignment) override
 Pre-allocates memory for bytes consecutive bytes with alignment requirement align and returns a pointer to the beginning of this memory.
 
Var< Ptr< void > > allocate (U32x1 bytes, uint32_t alignment) override
 Allocates memory for bytes consecutive bytes with alignment requirement align and returns a pointer to the beginning of this memory.
 
void deallocate (Ptr< void > ptr, U32x1 bytes) override
 Deallocates the bytes consecutive bytes of allocated memory at address ptr.
 
uint32_t perform_pre_allocations () override
 Performs the actual pre-allocations.
 
uint32_t pre_allocated_memory_consumption () const override
 Returns the pre-allocated memory overall consumption.
 
U32x1 allocated_memory_consumption () const override
 Returns the allocated memory overall consumption.
 
U32x1 allocated_memory_peak () const override
 Returns the allocated memory peak consumption.
 
Var< Ptr< void > > allocate (uint32_t bytes, uint32_t align=1)
 
void deallocate (Ptr< void > ptr, uint32_t bytes)
 
template<dsl_primitive T>
T * raw_malloc ()
 Pre-allocates memory for exactly one value of type.
 
template<dsl_primitive T>
T * raw_malloc (uint32_t count)
 Pre-allocates memory for an array of count consecutive values of type.
 
template<dsl_primitive T, std::size_t L = 1>
Ptr< PrimitiveExpr< T, L > > pre_malloc ()
 Pre-allocates memory for exactly one value of type.
 
template<dsl_primitive T, std::size_t L = 1>
Ptr< PrimitiveExpr< T, L > > pre_malloc (uint32_t count)
 Pre-allocates memory for an array of count consecutive values of type.
 
template<dsl_primitive T, std::size_t L = 1>
Var< Ptr< PrimitiveExpr< T, L > > > malloc ()
 Allocates memory for exactly one value of type.
 
template<dsl_primitive T, std::size_t L = 1, typename U >
requires requires (U &&u) { U32x1(std::forward<U>(u)); }
Var< Ptr< PrimitiveExpr< T, L > > > malloc (U &&count)
 Allocates memory for an array of count consecutive values of type.
 
template<primitive_convertible T>
requires requires (T &&t) { primitive_expr_t<T>(std::forward<T>(t)).template to<void*>(); }
void free (T &&ptr)
 Frees exactly one value of type.
 
void free (T &&ptr, U &&count)
 

Data Fields

template<primitive_convertible T, typename U >
 and { primitive_expr_t<T>(std::forward<T>(t)).template to<void*>()
 Frees count consecutive values of type.
 

Private Member Functions

void align_pre_memory (uint32_t alignment)
 Aligns the memory for pre-allocations with alignment requirement align.
 
void align_memory (uint32_t alignment)
 Aligns the memory for allocations with alignment requirement align.
 

Private Attributes

const memory::AddressSpacememory_
 

‍the underlying virtual address space used


 
bool pre_allocations_performed_ = false
 

‍flag whether pre-allocations were already performed, i.e. perform_pre_allocations() was already called


 
uint32_t pre_alloc_addr_
 

‍compile-time size of the currently used memory, used as pointer to next free pre-allocation


 
Global< U32x1 > alloc_addr_
 

‍runtime global size of the currently used memory, used as pointer to next free allocation


 
uint32_t pre_alloc_total_mem_ = 0
 

‍compile-time total memory consumption


 
Global< U32x1 > alloc_total_mem_
 

‍runtime total memory consumption


 
Global< U32x1 > alloc_peak_mem_
 

‍runtime peak memory consumption


 

Detailed Description

A simple linear allocator which keeps a global pointer to the next free memory address and advances it for allocation.

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 217 of file WasmDSL.cpp.

Constructor & Destructor Documentation

◆ LinearAllocator()

LinearAllocator::LinearAllocator ( const memory::AddressSpace memory,
uint32_t  start_addr 
)
inline

Definition at line 236 of file WasmDSL.cpp.

References M_insist.

◆ ~LinearAllocator()

LinearAllocator::~LinearAllocator ( )
inline

Definition at line 248 of file WasmDSL.cpp.

References M_insist.

Member Function Documentation

◆ align_memory()

void LinearAllocator::align_memory ( uint32_t  alignment)
inlineprivate

Aligns the memory for allocations with alignment requirement align.

Definition at line 317 of file WasmDSL.cpp.

References m::is_pow_2(), and M_insist.

◆ align_pre_memory()

void LinearAllocator::align_pre_memory ( uint32_t  alignment)
inlineprivate

Aligns the memory for pre-allocations with alignment requirement align.

Definition at line 312 of file WasmDSL.cpp.

References m::is_pow_2(), and M_insist.

◆ allocate() [1/2]

Var< Ptr< void > > LinearAllocator::allocate ( U32x1  bytes,
uint32_t  align 
)
inlineoverridevirtual

Allocates memory for bytes consecutive bytes with alignment requirement align and returns a pointer to the beginning of this memory.

Implements m::wasm::Allocator.

Definition at line 278 of file WasmDSL.cpp.

References m::is_pow_2(), M_insist, m::wasm::Select(), m::memory::AddressSpace::size(), and Wasm_insist.

◆ allocate() [2/2]

Var< Ptr< void > > m::wasm::Allocator::allocate ( uint32_t  bytes,
uint32_t  align = 1 
)
inlineinherited

Definition at line 6518 of file WasmDSL.hpp.

References m::wasm::Allocator::allocate().

Referenced by m::wasm::Allocator::allocate().

◆ allocated_memory_consumption()

U32x1 LinearAllocator::allocated_memory_consumption ( ) const
inlineoverridevirtual

Returns the allocated memory overall consumption.

Implements m::wasm::Allocator.

Definition at line 307 of file WasmDSL.cpp.

◆ allocated_memory_peak()

U32x1 LinearAllocator::allocated_memory_peak ( ) const
inlineoverridevirtual

Returns the allocated memory peak consumption.

Implements m::wasm::Allocator.

Definition at line 308 of file WasmDSL.cpp.

◆ deallocate() [1/2]

void LinearAllocator::deallocate ( Ptr< void >  ptr,
U32x1  bytes 
)
inlineoverridevirtual

Deallocates the bytes consecutive bytes of allocated memory at address ptr.

Implements m::wasm::Allocator.

Definition at line 291 of file WasmDSL.cpp.

References IF, and Wasm_insist.

◆ deallocate() [2/2]

void m::wasm::Allocator::deallocate ( Ptr< void >  ptr,
uint32_t  bytes 
)
inlineinherited

Definition at line 6519 of file WasmDSL.hpp.

References m::wasm::Allocator::deallocate().

Referenced by m::wasm::Allocator::deallocate().

◆ free() [1/2]

template<primitive_convertible T>
requires requires (T &&t) { primitive_expr_t<T>(std::forward<T>(t)).template to<void*>(); }
void m::wasm::Allocator::free ( T &&  ptr)
inlineinherited

Frees exactly one value of type.

Template Parameters
Tof allocated memory pointed by ptr.

Definition at line 6577 of file WasmDSL.hpp.

References m::wasm::Allocator::free().

Referenced by m::wasm::Allocator::free().

◆ free() [2/2]

void m::wasm::Allocator::free ( T &&  ptr,
U &&  count 
)
inlineinherited

Definition at line 6583 of file WasmDSL.hpp.

References m::wasm::L, and m::T().

◆ malloc() [1/2]

template<dsl_primitive T, std::size_t L = 1>
Var< Ptr< PrimitiveExpr< T, L > > > m::wasm::Allocator::malloc ( )
inlineinherited

Allocates memory for exactly one value of type.

Template Parameters
Tand number of SIMD lanes
L.Returns a pointer to this memory.

Definition at line 6532 of file WasmDSL.hpp.

◆ malloc() [2/2]

template<dsl_primitive T, std::size_t L = 1, typename U >
requires requires (U &&u) { U32x1(std::forward<U>(u)); }
Var< Ptr< PrimitiveExpr< T, L > > > m::wasm::Allocator::malloc ( U &&  count)
inlineinherited

Allocates memory for an array of count consecutive values of type.

Template Parameters
Tand number of SIMD lanes
L.Returns a pointer to this memory.

Definition at line 6553 of file WasmDSL.hpp.

References m::wasm::L, and m::T().

◆ perform_pre_allocations()

uint32_t LinearAllocator::perform_pre_allocations ( )
inlineoverridevirtual

Performs the actual pre-allocations.

Must be called exactly once after the last pre-allocation was requested. Returns the initial allocation address, i.e. an address after the last pre-allocated address.

Implements m::wasm::Allocator.

Definition at line 298 of file WasmDSL.cpp.

References m::wasm::Module::Get(), and M_insist.

◆ pre_allocate()

Ptr< void > LinearAllocator::pre_allocate ( uint32_t  bytes,
uint32_t  align 
)
inlineoverridevirtual

Pre-allocates memory for bytes consecutive bytes with alignment requirement align and returns a pointer to the beginning of this memory.

Implements m::wasm::Allocator.

Definition at line 265 of file WasmDSL.cpp.

References m::is_pow_2(), M_insist, and m::memory::AddressSpace::size().

◆ pre_allocated_memory_consumption()

uint32_t LinearAllocator::pre_allocated_memory_consumption ( ) const
inlineoverridevirtual

Returns the pre-allocated memory overall consumption.

Implements m::wasm::Allocator.

Definition at line 306 of file WasmDSL.cpp.

◆ pre_malloc() [1/2]

template<dsl_primitive T, std::size_t L = 1>
Ptr< PrimitiveExpr< T, L > > m::wasm::Allocator::pre_malloc ( )
inlineinherited

Pre-allocates memory for exactly one value of type.

Template Parameters
Tand number of SIMD lanes
L.Returns a pointer to this memory.

Definition at line 6528 of file WasmDSL.hpp.

◆ pre_malloc() [2/2]

template<dsl_primitive T, std::size_t L = 1>
Ptr< PrimitiveExpr< T, L > > m::wasm::Allocator::pre_malloc ( uint32_t  count)
inlineinherited

Pre-allocates memory for an array of count consecutive values of type.

Template Parameters
Tand number of SIMD lanes
L.Returns a pointer to this memory.

Definition at line 6541 of file WasmDSL.hpp.

References m::wasm::L, and m::T().

◆ raw_allocate()

void * LinearAllocator::raw_allocate ( uint32_t  bytes,
uint32_t  align 
)
inlineoverridevirtual

Pre-allocates memory for bytes consecutive bytes with alignment requirement align and returns a raw pointer to the beginning of this memory.

Implements m::wasm::Allocator.

Definition at line 252 of file WasmDSL.cpp.

References m::memory::AddressSpace::addr(), m::is_pow_2(), M_insist, and m::memory::AddressSpace::size().

◆ raw_malloc() [1/2]

template<dsl_primitive T>
T * m::wasm::Allocator::raw_malloc ( )
inlineinherited

Pre-allocates memory for exactly one value of type.

Template Parameters
T.Returns a raw pointer to this memory.

Definition at line 6524 of file WasmDSL.hpp.

References m::T().

◆ raw_malloc() [2/2]

template<dsl_primitive T>
T * m::wasm::Allocator::raw_malloc ( uint32_t  count)
inlineinherited

Pre-allocates memory for an array of count consecutive values of type.

Template Parameters
T.Returns a raw pointer to this memory.

Definition at line 6537 of file WasmDSL.hpp.

References m::T().

Field Documentation

◆ alloc_addr_

Global<U32x1> LinearAllocator::alloc_addr_
private

‍runtime global size of the currently used memory, used as pointer to next free allocation

Definition at line 227 of file WasmDSL.cpp.

◆ alloc_peak_mem_

Global<U32x1> LinearAllocator::alloc_peak_mem_
private

‍runtime peak memory consumption

Definition at line 233 of file WasmDSL.cpp.

◆ alloc_total_mem_

Global<U32x1> LinearAllocator::alloc_total_mem_
private

‍runtime total memory consumption

Definition at line 231 of file WasmDSL.cpp.

◆ and

template<primitive_convertible T, typename U >
m::wasm::Allocator::and { primitive_expr_t<T>(std::forward<T>(t)).template to<void*>()
inherited

Frees count consecutive values of type.

Template Parameters
Tof allocated memory pointed by ptr.

Definition at line 6581 of file WasmDSL.hpp.

◆ memory_

const memory::AddressSpace& LinearAllocator::memory_
private

‍the underlying virtual address space used

Definition at line 221 of file WasmDSL.cpp.

◆ pre_alloc_addr_

uint32_t LinearAllocator::pre_alloc_addr_
private

‍compile-time size of the currently used memory, used as pointer to next free pre-allocation

Definition at line 225 of file WasmDSL.cpp.

◆ pre_alloc_total_mem_

uint32_t LinearAllocator::pre_alloc_total_mem_ = 0
private

‍compile-time total memory consumption

Definition at line 229 of file WasmDSL.cpp.

◆ pre_allocations_performed_

bool LinearAllocator::pre_allocations_performed_ = false
private

‍flag whether pre-allocations were already performed, i.e. perform_pre_allocations() was already called

Definition at line 223 of file WasmDSL.cpp.


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