Class: SGC::Memory::Buffer

Inherits:
Object
  • Object
show all
Includes:
IBuffer
Defined in:
lib/memory/buffer.rb

Overview

A memory buffer class which implements IBuffer interface.

See Also:

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Object) initialize(type, size)



45
46
47
48
49
50
51
52
# File 'lib/memory/buffer.rb', line 45

def initialize(type, size)
    @@reads[type] && @@writes[type] or raise "Invalid buffer element type."

    @reader = @@reads[type]
    @writer = @@writes[type]
    @ptr = FFI::MemoryPointer.new(type, size)
    @size = size
end

Class Method Details

+ (Integer) element_size(type)



108
109
110
# File 'lib/memory/buffer.rb', line 108

def self.element_size(type)
    @@sizes[type]
end

Instance Method Details

- (Object) [](index)



57
58
59
60
# File 'lib/memory/buffer.rb', line 57

def [](index)
    assert_index(index)
    @ptr[index].send(@reader)
end

- (Object) []=(index, value)

Set the element at index of this buffer to value.



67
68
69
70
71
# File 'lib/memory/buffer.rb', line 67

def []=(index, value)
    assert_index(index)
    @ptr[index].send(@writer, value)
    value
end

- (Integer) element_size



81
82
83
# File 'lib/memory/buffer.rb', line 81

def element_size
    @ptr.type_size
end

- (MemoryPointer) offset(index)



100
101
102
103
# File 'lib/memory/buffer.rb', line 100

def offset(index)
    assert_index(index)
    MemoryPointer.new(@ptr[index])
end

- (Integer) size



75
76
77
# File 'lib/memory/buffer.rb', line 75

def size
    @size
end