carb::reallocate
Defined in carb/Memory.h
-
inline void *carb::reallocate(void *p, size_t size, size_t align = 0) noexcept
Reallocates a block of memory previously allocated with allocate().
This function changes the size of the memory block pointed to by
p
tosize
bytes withalign
alignment. The contents are unchanged from the start of the memory block up to the minimum of the old size andsize
. Ifsize
is larger than the old size, the added memory is not initialized. Ifp
isnullptr
, the call is equivalent toallocate(size, align)
; ifsize
is0
andp
is notnullptr
, the call is equivalent todeallocate(p)
. Unlessp
isnullptr
, it must have been retrieved by an earlier call to allocate() or reallocate(). If the memory region was moved in order to resize it,p
will be freed as withdeallocate(p)
.Note
Any plugin (or the executable) may allocate the memory and a different plugin (or the executable) may deallocate or reallocate it.
Note
If carb.dll/libcarb.so is not loaded, this function will always return
p
without side-effects.- Parameters
p – The block of memory previously returned from allocate() or reallocate() if resizing is resizing is desired. If
nullptr
is passed as this parameter, the call behaves as ifallocate(size, align)
was called.size – The size of the memory block requested, in bytes. See above for further explanation.
align – The minimum alignment (in bytes) of the memory block requested. Must be a power of two. Values less than
sizeof(size_t)
are ignored. Changing the alignment from a previous allocation is undefined behavior.0
indicates to use default system alignment (typically2 * sizeof(void*)
).
- Returns
A pointer to a block of memory of
size
bytes with minimum alignmentalign
, unless an error occurs in which casenullptr
is returned. Ifp
isnullptr
andsize
is0
thennullptr
is also returned.