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 to size bytes with align alignment. The contents are unchanged from the start of the memory block up to the minimum of the old size and size. If size is larger than the old size, the added memory is not initialized. If p is nullptr, the call is equivalent to allocate(size, align); if size is 0 and p is not nullptr, the call is equivalent to deallocate(p). Unless p is nullptr, 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 with deallocate(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 if allocate(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 (typically 2 * sizeof(void*)).

Returns

A pointer to a block of memory of size bytes with minimum alignment align, unless an error occurs in which case nullptr is returned. If p is nullptr and size is 0 then nullptr is also returned.