man rarray (Fonctions bibliothèques) - 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)), 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 CWbreak, CWcontinue, or CWgoto safely. All rarray functions can be called safely inside the RLIST_FOREACH macro except rarray_free(3). 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