carbReallocate

Defined in carb/Memory.h

void *carbReallocate(void *p, size_t size, size_t align)

Internal function used by all other allocation functions.

This function is the entry point into carb.dll/libcarb.so for carb::allocate(), carb::deallocate(), and carb::reallocate(). There are four modes to this function:

  • If p is nullptr and size is 0, no action is taken and nullptr is returned.

  • If p is not nullptr and size is 0, the given pointer is deallocated and nullptr is returned.

  • If p is nullptr and size is non-zero, memory of the requested size and alignment specified by align is allocated and returned. If an allocation error occurs, nullptr is returned.

  • If p is not nullptr and size is non-zero, the memory is reallocated and copied (as if by std::memcpy) to the new memory block, which is returned. If p can be resized in situ, the same p value is returned. If an error occurs, nullptr is returned.

Note

Using this function requires explicitly linking with carb.dll/libcarb.so if CARB_REQUIRE_LINKED is 1. Otherwise, the caller must ensure that carb.dll/libcarb.so is already loaded before calling this function. Use in situations where the Carbonite Framework is already loaded (i.e. plugins) does not require explicitly linking against Carbonite as this function will be found dynamically at runtime.

Warning

Do not call this function directly. Instead call carb::allocate(), carb::deallocate(), or carb::reallocate()

Parameters
  • p – The pointer to re-allocate or free. May be nullptr. See explanation above.

  • size – The requested size of the memory region in bytes. See explanation above.

  • align – The requested alignment of the memory region in bytes. Must be a power of two. See explanation above.

Returns

Allocated memory, or nullptr upon deallocation, or nullptr on allocation when an error occurs.