---
name: "rarray_new"
section: "3"
platform: "linux"
package: "libroy-dev"
version: "1.0.8-1"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/rarray_new"
---

# rarray\_new(3)

allocate and initialize a new Roy array. rarray\_free - free storage of Roy array.

## NAME

rarray\_new - allocate and initialize a new Roy array.

rarray\_free - free storage of Roy array.

## SYNOPSIS

\#include \<roy.h\>

RArray \* rarray\_new (unsigned int *element\_size*, unsigned int *elements\_per\_chunk*);

void rarray\_free (RArray \**array*);

## DESCRIPTION

[*rarray\_new*(3)](/rarray_new/3.md) creates a new Roy array, allocating the first contigious chunk of memory of size *element\_size* \* *elements\_per\_chunk*. *element\_size* should be the size of the element in bytes, and  *elements\_per\_chunk* is the number of elements to allocate at a time. These parameters determine how large the contigious blocks of memory are.  Once your array grows past the end of the current block, a new block of this size is allocated, and appended to the array.

If the array is shrunk in any manner, the blocks are not freed, instead, they are left around in case of later expansion.  The blocks are only freed when [*rarray\_free*(3)](/rarray_free/3.md) is called.

[*rarray\_free*(3)](/rarray_free/3.md) frees *array*, and all of the blocks in the array.  This effectively frees all elements of the array.

## RETURN VALUE

[*rarray\_new*(3)](/rarray_new/3.md) returns a pointer to a new RArray. [*rarray\_free*(3)](/rarray_free/3.md) does not return a value.

## ERRORS

These calls produce no errors.

## SEE ALSO

[*rarray*(3)](/rarray/3.md), [*rarray\_append*(3)](/rarray_append/3.md),  [*rarray\_free*(3)](/rarray_free/3.md), [*rarray\_last*(3)](/rarray_last/3.md),  [*rarray\_len*(3)](/rarray_len/3.md), [*rarray\_nth*(3)](/rarray_nth/3.md),  [*rarray\_peek*(3)](/rarray_peek/3.md), [*rarray\_pop*(3)](/rarray_pop/3.md),  [*rarray\_push*(3)](/rarray_push/3.md), [*rarray\_set\_len*(3)](/rarray_set_len/3.md),  [*roy*(3)](/roy/3.md)
