Class: FFI::ArrayType

Inherits:
Type
  • Object
show all
Defined in:
ext/ffi_c/ArrayType.c,
ext/ffi_c/ArrayType.c

Overview

This is a typed array. The type is a native type.

Constant Summary

Constants inherited from Type

Type::Struct

Instance Method Summary collapse

Methods inherited from Type

#alignment, #inspect, #size

Constructor Details

#initialize(component_type, length) ⇒ self

A new instance of ArrayType.

Parameters:

  • component_type (Type)
  • length (Numeric)


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'ext/ffi_c/ArrayType.c', line 117

static VALUE
array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength)
{
    ArrayType* array;
    int i;

    TypedData_Get_Struct(self, ArrayType, &rbffi_array_type_data_type, array);

    array->length = NUM2UINT(rbLength);
    RB_OBJ_WRITE(self, &array->rbComponentType, rbComponentType);
    TypedData_Get_Struct(rbComponentType, Type, &rbffi_type_data_type, array->componentType);

    array->ffiTypes = xcalloc(array->length + 1, sizeof(*array->ffiTypes));
    array->base.ffiType->elements = array->ffiTypes;
    array->base.ffiType->size = array->componentType->ffiType->size * array->length;
    array->base.ffiType->alignment = array->componentType->ffiType->alignment;

    for (i = 0; i < array->length; ++i) {
        array->ffiTypes[i] = array->componentType->ffiType;
    }

    return self;
}

Instance Method Details

#element_typeType

Get element type.

Returns:



161
162
163
164
165
166
167
168
169
# File 'ext/ffi_c/ArrayType.c', line 161

static VALUE
array_type_element_type(VALUE self)
{
    ArrayType* array;

    TypedData_Get_Struct(self, ArrayType, &rbffi_array_type_data_type, array);

    return array->rbComponentType;
}

#lengthNumeric

Get array’s length

Returns:

  • (Numeric)


146
147
148
149
150
151
152
153
154
# File 'ext/ffi_c/ArrayType.c', line 146

static VALUE
array_type_length(VALUE self)
{
    ArrayType* array;

    TypedData_Get_Struct(self, ArrayType, &rbffi_array_type_data_type, array);

    return UINT2NUM(array->length);
}