class Fiddle::Pinned

Public Class Methods

# File ext/fiddle/lib/fiddle/ffi_backend.rb, line 546
def initialize(object)
  @object = object
end

Create a new pinned object reference. The Fiddle::Pinned instance will prevent the GC from moving object.

static VALUE
initialize(VALUE self, VALUE ref)
{
    struct pinned_data *data;
    TypedData_Get_Struct(self, struct pinned_data, &pinned_data_type, data);
    RB_OBJ_WRITE(self, &data->ptr, ref);
    return self;
}

Public Instance Methods

Clear the reference to the object this is pinning.

# File ext/fiddle/lib/fiddle/ffi_backend.rb, line 557
def clear
  @object = nil
end

Returns true if the reference has been cleared, otherwise returns false.

# File ext/fiddle/lib/fiddle/ffi_backend.rb, line 561
def cleared?
  @object.nil?
end

Return the object that this pinned instance references.

# File ext/fiddle/lib/fiddle/ffi_backend.rb, line 550
def ref
  if @object.nil?
    raise ClearedReferenceError, "`ref` called on a cleared object"
  end
  @object
end