Module: Snow::CStruct::StructArrayBase::Allocators

Defined in:
lib/snow-data/c_struct/array_base.rb,
lib/snow-data/c_struct/array_base.rb

Instance Method Summary collapse

Instance Method Details

#alloca(length, &block) ⇒ Object



149
150
151
152
153
154
155
156
# File 'lib/snow-data/c_struct/array_base.rb', line 149

def alloca(length, &block)
  __alloca__(length * self::BASE::SIZE) {
    |mem|
    mem.instance_variable_set(:@length, length)
    mem.instance_variable_set(:@__cache__, nil)
    yield(mem)
  }
end

#new(length) ⇒ Object Also known as: []

:nodoc:

Raises:

  • (ArgumentError)


138
139
140
141
142
143
144
145
# File 'lib/snow-data/c_struct/array_base.rb', line 138

def new(length) # :nodoc:
  length = length.to_i
  raise ArgumentError, "Length must be greater than zero" if length < 1
  inst = __malloc__(length * self::BASE::SIZE, self::BASE::ALIGNMENT)
  inst.instance_variable_set(:@length, length)
  inst.instance_variable_set(:@__cache__, nil)
  inst
end

#wrap(address, length_in_elements) ⇒ Object

:nodoc:



133
134
135
# File 'lib/snow-data/c_struct/array_base.rb', line 133

def wrap(address, length_in_elements) # :nodoc:
  __wrap__(address, length_in_elements * self::BASE::SIZE)
end