Class: FFI::ArrayType
- 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
Instance Method Summary collapse
-
#element_type ⇒ Type
Get element type.
-
#initialize(component_type, length) ⇒ self
constructor
A new instance of ArrayType.
-
#length ⇒ Numeric
Get array’s length.
Methods inherited from Type
Constructor Details
#initialize(component_type, length) ⇒ self
A new instance of ArrayType.
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_type ⇒ Type
Get element type.
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;
}
|
#length ⇒ Numeric
Get array’s length
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);
}
|