MmapPool.reallocate

Increases or decreases the size of a memory block.

class MmapPool
@nogc @trusted nothrow
bool
reallocate
(
ref void[] p
,
size_t size
)

Parameters

p void[]

A pointer to the memory block.

size size_t

Size of the reallocated block.

Return Value

Type: bool

Whether the reallocation was successful.

Examples

void[] p;
MmapPool.instance.reallocate(p, 10 * int.sizeof);
(cast(int[]) p)[7] = 123;

assert(p.length == 40);

MmapPool.instance.reallocate(p, 8 * int.sizeof);

assert(p.length == 32);
assert((cast(int[]) p)[7] == 123);

MmapPool.instance.reallocate(p, 20 * int.sizeof);
(cast(int[]) p)[15] = 8;

assert(p.length == 80);
assert((cast(int[]) p)[15] == 8);
assert((cast(int[]) p)[7] == 123);

MmapPool.instance.reallocate(p, 8 * int.sizeof);

assert(p.length == 32);
assert((cast(int[]) p)[7] == 123);

MmapPool.instance.deallocate(p);

Meta