Class: SGC::Memory::MemoryPointer

Inherits:
Object
  • Object
show all
Defined in:
lib/memory/pointer.rb

Overview

A memory pointer class. TODO: To use #write_pointer() when FFI fix the use of FIX2INT().

Instance Method Summary collapse

Constructor Details

#initialize(addr = nil) ⇒ Object



37
38
39
40
# File 'lib/memory/pointer.rb', line 37

def initialize(addr = nil)
    @p = FFI::MemoryPointer.new(:pointer)
    @p.write_long(addr.to_i)
end

Instance Method Details

#offset(index) ⇒ MemoryPointer



59
60
61
# File 'lib/memory/pointer.rb', line 59

def offset(index)
    MemoryPointer.new(@p.read_pointer.to_i + index)
end

#ptrObject



44
45
46
# File 'lib/memory/pointer.rb', line 44

def ptr
    @p.read_pointer
end

#ptr=(addr) ⇒ Object

Set this pointer to point to memory address addr.



52
53
54
# File 'lib/memory/pointer.rb', line 52

def ptr=(addr)
    @p.write_long(addr.to_i)
end

#refObject



65
66
67
# File 'lib/memory/pointer.rb', line 65

def ref
    @p
end