Class: FFI::ManagedStruct
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Struct
|
|
|
Instance Chain:
self,
Struct
|
|
| Inherits: |
FFI::Struct
|
| Defined in: | lib/ffi/managedstruct.rb |
Overview
ManagedStruct allows custom garbage-collection of your FFI::Structs.
The typical use case would be when interacting with a library that has a nontrivial memory management design, such as a linked list or a binary tree.
When the Struct instance is garbage collected, ManagedStruct will invoke the class’s release() method during object finalization.
Class Attribute Summary
Class Method Summary
-
.new(pointer) ⇒ ManagedStruct
constructor
A new instance of
ManagedStruct.
Struct - Inherited
| .alignment, .auto_ptr, .by_ref, .by_value, .in, .layout, .members, | |
| .offset_of | Get the offset of a field. |
| .offsets | Get an array of tuples (field name, offset of the field). |
| .out, .ptr, .val, | |
| .array_layout | Add array |
| .hash_layout | Add hash |
Instance Method Summary
Struct - Inherited
| #align | Alias for Struct#alignment. |
| #alignment, | |
| #clear | Clear the struct content. |
| #members, | |
| #offset_of | Get the offset of a field. |
| #offsets | Get an array of tuples (field name, offset of the field). |
| #size | Get struct size. |
| #to_ptr | Get |
| #values | Get array of values from |
Constructor Details
.new(pointer) ⇒ ManagedStruct
.new ⇒ ManagedStruct
ManagedStruct
.new ⇒ ManagedStruct
A new instance of ManagedStruct.
# File 'lib/ffi/managedstruct.rb', line 77
def initialize(pointer=nil) raise NoMethodError, "release() not implemented for class #{self}" unless self.class.respond_to?(:release, true) raise ArgumentError, "Must supply a pointer to memory for the Struct" unless pointer super AutoPointer.new(pointer, self.class.method(:release)) end