Function MmapPool.reallocate
Increases or decreases the size of a memory block.
bool reallocate
(
ref void[] p,
ulong size
) nothrow @nogc @trusted;
Parameters
Name | Description |
---|---|
p | A pointer to the memory block. |
size | Size of the reallocated block. |
Returns
Whether the reallocation was successful.
Example
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);