reallocate#
Fully qualified name: carb::reallocate
Defined in carb/Memory.h
- inline void *carb::reallocate(
- void *p,
- size_t size,
- size_t align = 0,
Reallocates a block of memory previously allocated with allocate().
This function changes the size of the memory block pointed to by
ptosizebytes withalignalignment. The contents are unchanged from the start of the memory block up to the minimum of the old size andsize. Ifsizeis larger than the old size, the added memory is not initialized. Ifpisnullptr, the call is equivalent toallocate(size, align); ifsizeis0andpis notnullptr, the call is equivalent todeallocate(p). Unlesspisnullptr, it must have been retrieved by an earlier call to allocate() or reallocate(). If the memory region was moved in order to resize it,pwill 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
pwithout side-effects.- Parameters:
p – The block of memory previously returned from allocate() or reallocate() if resizing is resizing is desired. If
nullptris 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.0indicates to use default system alignment (typically2 * sizeof(void*)).
- Returns:
A pointer to a block of memory of
sizebytes with minimum alignmentalign, unless an error occurs in which casenullptris returned. Ifpisnullptrandsizeis0thennullptris also returned.