Class: SGC::Memory::MemoryPointer
- Inherits:
-
Object
- Object
- SGC::Memory::MemoryPointer
- 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
-
#initialize(addr = nil) ⇒ Object
constructor
A memory pointer pointing to address addr.
-
#offset(index) ⇒ MemoryPointer
A memory pointer pointing to the index byte.
-
#ptr ⇒ Object
The internal pointer representation.
-
#ptr=(addr) ⇒ Object
Set this pointer to point to memory address addr.
-
#ref ⇒ Object
The internal representation of a pointer pointing to this memory pointer.
Constructor Details
#initialize(addr = nil) ⇒ Object
Returns A memory pointer pointing to address addr.
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
Returns A memory pointer pointing to the index byte.
59 60 61 |
# File 'lib/memory/pointer.rb', line 59 def offset(index) MemoryPointer.new(@p.read_pointer.to_i + index) end |
#ptr ⇒ Object
Returns The internal pointer representation.
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 |
#ref ⇒ Object
Returns The internal representation of a pointer pointing to this memory pointer.
65 66 67 |
# File 'lib/memory/pointer.rb', line 65 def ref @p end |