In Files

Parent

FFI::MemoryPointer

A MemoryPointer is a specific {Pointer}. It points to a memory composed of cells. All cells have the same size.

@example Create a new MemoryPointer

mp = FFI::MemoryPointer.new(:long, 16)   # Create a pointer on a memory of 16 long ints.

@example Create a new MemoryPointer from a String

mp1 = FFI::MemoryPointer.from_string("this is a string")
# same as:
mp2 = FFI::MemoryPointer.new(:char,16)
mp2.put_string("this is a string")

Public Class Methods

from_string(s) click to toggle source
@param [String] s string
@return [MemoryPointer]
Create a {MemoryPointer} with +s+ inside.
static VALUE
memptr_s_from_string(VALUE klass, VALUE to_str)
{
    VALUE s = StringValue(to_str);
    VALUE args[] = { INT2FIX(1), LONG2NUM(RSTRING_LEN(s) + 1), Qfalse };
    VALUE obj = rb_class_new_instance(3, args, klass);
    rb_funcall(obj, rb_intern("put_string"), 2, INT2FIX(0), s);

    return obj;
}
initialize(size, count=1, clear=true) click to toggle source
@param [Fixnum, Bignum, Symbol, FFI::Type] size size of a memory cell (in bytes, or type whom size will be used)
@param [Numeric] count number of cells in memory
@param [Boolean] clear set memory to all-zero if +true+
@return [self]
A new instance of FFI::MeoryPointer.
static VALUE
memptr_initialize(int argc, VALUE* argv, VALUE self)
{
    VALUE size = Qnil, count = Qnil, clear = Qnil;
    int nargs = rb_scan_args(argc, argv, "12", &size, &count, &clear);

    memptr_malloc(self, rbffi_type_size(size), nargs > 1 ? NUM2LONG(count) : 1,
        RTEST(clear) || clear == Qnil);

    if (rb_block_given_p()) {
        return rb_ensure(rb_yield, self, memptr_free, self);
    }

    return self;
}

[Validate]

Generated with the Darkfish Rdoc Generator 2.