---
name: "iarray_allocate"
section: "3"
platform: "linux"
package: "libowfat-dev"
version: "0.32-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/iarray_allocate"
---

# iarray\_allocate(3)

get pointer to nth element in iarray

## NAME

iarray\_allocate - get pointer to nth element in iarray

## SYNTAX

**#include \<libowfat/iarray.h\>**

void\* **iarray\_allocate**(iarray\* *x*, size\_t *pos*);

  iarray *x*;\
   size\_t *pos*;\
   *t*\* p = iarray\_allocate(&*x*,*pos*);

## DESCRIPTION

iarray\_allocate is similar to iarray\_get, but if the requested element is not in the array, the array will be resized.  If the resize fails, iarray\_allocate returns NULL and leaves the array untouched.

This function is safe to use in environments with multiple threads, but it can block for indeterminate time if other threads are reallocating the array at the same time.

Note that it is safe to use iarray\_allocate where you would otherwise use iarray\_get.  The only reason to use iarray\_get over iarray\_allocate would be optimization.

## RETURN VALUE

Return a pointer to the requested element.  If there was a memory allocation failure, returns NULL.

## SEE ALSO

[iarray\_init(3)](/iarray_init/3.md), [iarray\_get(3)](/iarray_get/3.md), [iarray\_free(3)](/iarray_free/3.md)
