Skip to content

Instantly share code, notes, and snippets.

@albanpeignier
Created May 19, 2009 20:35
Show Gist options
  • Save albanpeignier/114378 to your computer and use it in GitHub Desktop.
Save albanpeignier/114378 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'ffi'
pointer = FFI::MemoryPointer.new(:char, 3)
puts "pointer: #{pointer.inspect} (#{pointer.type_size})"
# => pointer: #<MemoryPointer address=0x1713e50 size=3> (1)
first = pointer + pointer.type_size
puts "first: #{first.inspect}"
# => first: #<Native Pointer address=0x1713e51>
second = first + pointer.type_size
puts "second: #{second.inspect}"
# => second: #<Native Pointer address=0x1713e52>
first = pointer[1]
puts "first: #{first.inspect}"
# => first: #<Native Pointer address=0x1713e51>
second = first[1]
puts "second: #{second.inspect}"
# => test_plus.rb:16: undefined method `[]' for #<Native Pointer address=0x1713e51> (NoMethodError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment