class FFI::ArrayType

This is a typed array. The type is a {NativeType native type}.

Public Class Methods

initialize(component_type, length) click to toggle source
@param [Type] component_type
@param [Numeric] length
@return [self]
A new instance of ArrayType.
static VALUE
array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength)
{
    ArrayType* array;
    int i;

    Data_Get_Struct(self, ArrayType, array);

    array->length = NUM2UINT(rbLength);
    array->rbComponentType = rbComponentType;
    Data_Get_Struct(rbComponentType, 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;
}

Public Instance Methods

element_type click to toggle source
@return [Type]
Get element type.
static VALUE
array_type_element_type(VALUE self)
{
    ArrayType* array;

    Data_Get_Struct(self, ArrayType, array);

    return array->rbComponentType;
}
length click to toggle source
@return [Numeric]
Get array's length
static VALUE
array_type_length(VALUE self)
{
    ArrayType* array;

    Data_Get_Struct(self, ArrayType, array);

    return UINT2NUM(array->length);
}