GC.realloc

Extend, shrink or allocate a new block of memory keeping the contents of an existing block

If sz is zero, the memory referenced by p will be deallocated as if by a call to free. If p is null, new memory will be allocated via malloc. If p is pointing to memory not allocated from the GC or to the interior of an allocated memory block, no operation is performed and null is returned.

Otherwise, a new memory block of size sz will be allocated as if by a call to malloc, or the implementation may instead resize or shrink the memory block in place. The contents of the new memory block will be the same as the contents of the old memory block, up to the lesser of the new and old sizes.

The caller guarantees that there are no other live pointers to the passed memory block, still it might not be freed immediately by realloc. The garbage collector can reclaim the memory block in a later collection if it is unused. If allocation fails, this function will throw an OutOfMemoryError.

If ba is zero (the default) the attributes of the existing memory will be used for an allocation. If ba is not zero and no new memory is allocated, the bits in ba will replace those of the current memory block.

struct GC
version(D_ProfileGC)
extern (C) pragma(mangle, "gc_reallocTrace") static pure nothrow
void*
realloc
(
return scope void* p
,
size_t sz
,
uint ba = 0
,
const TypeInfo ti = null
,
string file = __FILE__
,
int line = __LINE__
,
string func = __FUNCTION__
)

Parameters

p void*

A pointer to the base of a valid memory block or to null.

sz size_t

The desired allocation size in bytes.

ba uint

A bitmask of the BlkAttr attributes to set on this block.

ti TypeInfo

TypeInfo to describe the memory. The GC might use this information to improve scanning for pointers or to call finalizers.

Return Value

Type: void*

A reference to the allocated memory on success or null if sz is zero or the pointer does not point to the base of an GC allocated memory block.

Throws

OutOfMemoryError on allocation failure.

Suggestion Box / Bug Report