Class: Yadriggy::C::IntArray

Inherits:
FFIArray show all
Defined in:
lib/yadriggy/c/ffi.rb

Overview

Array of 32bit integers. In C, the type of this array is arrayof(Int).

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FFIArray

#==, #length, #memory_pointer, #set_values, #size, #to_a

Constructor Details

#initialize(size, ptr = nil) ⇒ IntArray

Returns a new instance of IntArray.

Parameters:

  • size (Integer)

    array size.

  • ptr (FFI::MemoryPointer) (defaults to: nil)

    a memory pointer or nil. If nil, a new memory block is allocated.



56
57
58
59
60
61
62
# File 'lib/yadriggy/c/ffi.rb', line 56

def initialize(size, ptr=nil)
  if ptr.nil?
    @array = FFI::MemoryPointer.new(:int32, size)
  else
    @array = ptr
  end
end

Class Method Details

.element_typeObject



72
73
74
# File 'lib/yadriggy/c/ffi.rb', line 72

def self.element_type()
  Integer
end

Instance Method Details

#[](index) ⇒ Object



64
65
66
# File 'lib/yadriggy/c/ffi.rb', line 64

def [](index)
  @array.get_int32(index * 4)
end

#[]=(index, value) ⇒ Object



68
69
70
# File 'lib/yadriggy/c/ffi.rb', line 68

def []=(index, value)
  @array.put_int32(index * 4, value)
end