omp_realloc (GNU libgomp)

#### 3.13.9 `omp_realloc` – Reallocate memory allocated with OpenMP routines ¶

Description:

  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 as ptr 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`. If free_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 the def-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 the free_allocator and allocator arguments may only be a constant expression with the value of one of the predefined allocators and may not be `omp_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.

C:

  Prototype: | `void* omp_realloc(void *ptr, size_t size,`
  | `omp_allocator_handle_t allocator,`
  | `omp_allocator_handle_t free_allocator)`

C++:

  Prototype: | `void* omp_realloc(void *ptr, size_t size,`
  | `omp_allocator_handle_t allocator=omp_null_allocator,`
  | `omp_allocator_handle_t free_allocator=omp_null_allocator)`

Fortran:

  Interface: | `type(c_ptr) function omp_realloc(ptr, size, allocator, free_allocator) bind(C)`
  | `use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t`
  | `type(C_ptr), value :: ptr`
  | `integer (c_size_t), value :: size`
  | `integer (omp_allocator_handle_kind), value :: allocator, free_allocator`

See also:

  `OMP_ALLOCATOR` – Set the default allocator, Memory allocation, `omp_set_default_allocator` – Set the default allocator, `omp_free` – Freeing memory allocated with OpenMP routines, `omp_init_allocator` – Create an allocator

Reference:

  OpenMP specification v5.0, Section 3.7.9