omp_realloc (GNU libgomp) (original) (raw)
The omp_realloc
routine deallocates memory to which ptr points to and allocates new memory with the specified allocator argument; the new memory will have the content of the old memory up to the minimum of the old size and the new size, otherwise the content of the returned memory is unspecified. If the new allocator is the same as the old one, the routine tries to resize the existing memory allocation, returning the same address asptr if successful. ptr must point to memory allocated by an OpenMP memory-management routine.
The allocator and free_allocator arguments must be a predefined allocator, an allocator handle or omp_null_allocator
. Iffree_allocator is omp_null_allocator
, the implementation automatically determines the allocator used for the allocation of ptr. If allocator is omp_null_allocator
and ptr is not a null pointer, the same allocator as free_allocator
is used and when ptr is a null pointer the allocator specified by thedef-allocator-var ICV is used.
The size must be a nonnegative number denoting the number of bytes to be allocated; if size is zero, omp_realloc
will return free the memory and return a null pointer. When size is nonzero: if successful, a pointer to the allocated memory is returned, otherwise the fallback
trait of the allocator determines the behavior.
In target
regions, either the dynamic_allocators
clause must appear on a requires
directive in the same compilation unit – or thefree_allocator and allocator arguments may only be a constant expression with the value of one of the predefined allocators and may not beomp_null_allocator
.
Memory allocated by omp_realloc
must be freed using omp_free
. Calling omp_free
invokes undefined behavior if the memory was already deallocated or when the used allocator has already been destroyed.