---
name: "rarray"
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"
---

# rarray(3)

Roy variable sized arrays

## NAME

rchunk - Roy variable sized arrays

## SYNOPSIS

\#include \<roy.h\>

## DESCRIPTION

Implements variable sized arrays.  These arrays are allocated in chunks, with the each chunk pointing to the next.  This structure has the advantage that many of the entries are in order in memory, which allows you to walk them in order very fast, as this is usually the way that the cache is implemented.

If you are storing structures in the array, it also has the advantage that the members of the structure exist in the linear array, again increasing cache hits of the structure members.

They may also be used to implement stacks.

Thay are also used as a linked list replacement with less overhead (no next/previous pointers).

## RARRAY\_FOREACH (array, entry)

Because the array is broken up into chunks (see [*rarray\_new*(3)](/rarray_new/3.md)), in order to walk the array, you must use the RARRAY\_FOREACH macro.

This macro walks through the array, assigning 'entry' to the concequent array entry through each iteration.  The programmer can use `"break"`, `"continue"`, or `"goto"` safely.  All rarray functions can be called safely inside the RLIST\_FOREACH macro except [*rarray\_free*(3)](/rarray_free/3.md).  You also cannot remove the next item in the array, as a pointer is kept to it through each iteration.

- EXAMPLE

  To walk an array:

```
        MyEntry *entry;
        RArray *array;
```

```
        /* ... */
```

```
        RARRAY_FOREACH (array, entry) {
                /* do something with entry */
                entry->foo++;
        } RFOREACH_CLOSE;
```

## SEE ALSO

[*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\_new*(3)](/rarray_new/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)
