Ruby: RArray Struct Reference

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

Data Fields
RArray Struct Reference

Ruby's array. More...

`#include <rarray.h>`

## Data Fields
struct RBasic | basic
| Basic part, including flags and class.
union { |
struct { |
long len |
| Number of elements of the array. More...
union { |
long capa |
| Capacity of `*ptr`. More...
const VALUE shared_root |
| Parent of the array. More...
} aux |
| Auxiliary info. More...
const VALUE * ptr |
| Pointer to the C array that holds the elements of the array. More...
} heap |
| Arrays that use separated memory region for elements use this pattern. More...
const VALUE ary [RARRAY_EMBED_LEN_MAX] |
| Embedded elements. More...
} | as |
| Array's specific fields.

## Detailed Description

Ruby's array.

Definition at line 176 of file rarray.h.

## Field Documentation

## ◆ ary

const VALUE RArray::ary[RARRAY_EMBED_LEN_MAX]

Embedded elements.

When an array is short enough, it uses this area to store its elements. In this case the length is encoded into the flags.

Definition at line 239 of file rarray.h.

Referenced by rb_ary_aref(), rb_ary_cat(), rb_ary_dup(), rb_ary_each(), rb_ary_entry(), rb_ary_free(), rb_ary_freeze(), rb_ary_hidden_new(), rb_ary_join(), rb_ary_modify(), rb_ary_new_from_args(), rb_ary_pop(), rb_ary_push(), rb_ary_resize(), rb_ary_resurrect(), rb_ary_reverse(), rb_ary_rotate(), rb_ary_shift(), rb_ary_store(), rb_ary_subseq(), rb_ary_to_s(), rb_ary_unshift(), and rb_check_array_type().

## ◆ [union]

union { ... } RArray::as

Array's specific fields.

## ◆ [union]

union { ... } RArray::aux

Auxiliary info.

## ◆ basic

struct RBasic RArray::basic

Basic part, including flags and class.

Definition at line 179 of file rarray.h.

## ◆ capa

long RArray::capa

Capacity of `*ptr`.

A continuous memory region of at least `capa` elements is expected to exist at `*ptr`. This can be bigger than `len`.

Definition at line 201 of file rarray.h.

Referenced by rb_ary_hidden_new(), and rb_ary_new_capa().

## ◆ [struct]

struct { ... } RArray::heap

Arrays that use separated memory region for elements use this pattern.

## ◆ len

long RArray::len

Number of elements of the array.

Definition at line 191 of file rarray.h.

Referenced by rb_ary_cat(), rb_ary_dup(), rb_ary_join(), rb_ary_resize(), rb_ary_reverse(), rb_ary_rotate(), rb_ary_shift(), rb_ary_store(), and rb_ary_subseq().

## ◆ ptr

const VALUE* RArray::ptr

Pointer to the C array that holds the elements of the array.

In the old days each array had dedicated memory regions. That is no longer true today, but there still are arrays of such properties. This field could be used to point such things.

Definition at line 223 of file rarray.h.

Referenced by rb_ary_push(), rb_ary_resize(), and rb_ary_rotate().

## ◆ shared_root

const VALUE RArray::shared_root

Parent of the array.

Nowadays arrays can share their backend memory regions each other, constructing gigantic nest of objects. This situation is called "shared", and this is the field to control such properties.

Definition at line 214 of file rarray.h.

The documentation for this struct was generated from the following file:

- include/ruby/internal/core/rarray.h