### Home Classes Methods

### In Files

- ext/ffi_c/ffi.c

### Parent

FFI::Pointer

### Methods

- ::from_string
- ::new

### Files

- Makefile
- ChangeLog
- LICENSE
- README
- compile
- configure
- depcomp
- stamp-vti
- install-sh
- libtool-version
- mdate-sh
- missing

### Class/Module Index

Quicksearch

- FFI
- FFI::AbstractMemory
- FFI::AutoPointer
- FFI::AutoPointer::CallableReleaser
- FFI::AutoPointer::DefaultReleaser
- FFI::AutoPointer::Releaser
- FFI::ConstGenerator
- FFI::ConstGenerator::Constant
- FFI::DataConverter
- FFI::DynamicLibrary
- FFI::DynamicLibrary::Symbol
- FFI::Enum
- FFI::Enums
- FFI::Function
- FFI::FunctionType
- FFI::Generator
- FFI::Generator::Task
- FFI::IO
- FFI::LastError
- FFI::Library
- FFI::ManagedStruct
- FFI::MemoryPointer
- FFI::NativeType
- FFI::NotFoundError
- FFI::NullPointerError
- FFI::Platform
- FFI::PlatformError
- FFI::Pointer
- FFI::StrPtrConverter
- FFI::Struct
- FFI::Struct::InlineArray
- FFI::Struct::ManagedStructConverter
- FFI::StructByValue
- FFI::StructGenerator
- FFI::StructGenerator::Field
- FFI::StructLayout
- FFI::StructLayout::Enum
- FFI::StructLayout::InnerStruct
- FFI::StructLayout::Mapped
- FFI::StructLayoutBuilder
- FFI::Type
- FFI::Type::Builtin
- FFI::TypesGenerator
- FFI::Union
- FFI::VariadicInvoker

No matching classes.

# 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.