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

- (Object) initialize(addr = nil)

Returns A memory pointer pointing to address addr.

Parameters:

  • addr (Integer) (defaults to: nil)

    Memory address addr to initialize to.



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

- (MemoryPointer) offset(index)

Returns A memory pointer pointing to the index byte.

Parameters:

  • index (Integer)

    Index to a memory offset.

Returns:

  • (MemoryPointer)

    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

- (Object) ptr

Returns The internal pointer representation.

Returns:

  • The internal pointer representation.



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

def ptr
    @p.read_pointer
end

- (Object) ptr=(addr)

Set this pointer to point to memory address addr.

Parameters:

  • addr (Integer)

    Memory address to set to.

Returns:

  • addr.



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

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

- (Object) ref

Returns The internal representation of a pointer pointing to this memory pointer.

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