Marmos
v juptune
v asn1
v lang
v ast
v Classes
v Enums
v ir
v parser
v Enums
v Structs
v core
v crypto
v keyexchange
v memory
v data
v alphabet
v buffer
v json
v builder
v parser
v Enums
v Structs
v serialise
v Structs
v Templates
v pem
v Enums
v Structs

Functions MemoryBlockPool.allocate

1
2
3
4
5
6
7
module juptune.core.ds.block;

Result allocate(
    ulong powerOfTwo, 
    ulong blockCount, 
    MemoryBlockAllocation allocation
);

Documentation

Allocates a certain amount of blocks from the pool, at a specific power of two size.

Notes

Despite the name, this function doesn't actually allocate any memory from the system, but instead pulls from preallocated memory. In order to preallocate memory, use preallocateBlocksbeforehand.

There's loose protection against buggy double allocations and frees, but it's not perfect.

This function does not attempt to clamp the powerOfTwoparameter to the nearest valid value. If this value is out of range, an assert will fail. Please use MIN_BLOCK_POWERand MAX_BLOCK_POWERto clamp the value and handle user input error cases.

Performance

Where nis the blockCountparameter, on success this function is always O(n).

On failure, this function is at best O(1) if there are no free blocks, and at worst O(n-1) if there are free blocks. The latter case could be made O(1) by storing a free block count in each bucket, but I'm too lazy to do that right now.

The main time loss culprit on each iteration is likely either the underlying branch for the whileloop, or the repeated gapped memory access. So in otherwords, negligible at the expected small nvalues.

Params

Throws

MemoryBlockPool.Errors.notEnoughBlocksif there are not enough free blocks to satisfy the request.

Returns

Result.noErrorif the allocation was successful.

See Also

MemoryBlockAllocation, MemoryBlockPool.preallocateBlocks