Class: FFI::MemoryPointer
- Inherits:
-
Pointer
- Object
- AbstractMemory
- Pointer
- FFI::MemoryPointer
- Defined in:
- ext/ffi_c/MemoryPointer.c,
ext/ffi_c/MemoryPointer.c
Overview
A MemoryPointer is a specific Pointer. It points to a memory composed of cells. All cells have the same size.
Constant Summary
Constants inherited from Pointer
Constants inherited from AbstractMemory
Class Method Summary collapse
-
.from_string(s) ⇒ MemoryPointer
Create a MemoryPointer with
s
inside.
Instance Method Summary collapse
-
#initialize(size, count = 1, clear = true) ⇒ self
constructor
A new instance of FFI::MemoryPointer.
Methods inherited from Pointer
#+, #==, #address, #autorelease=, #autorelease?, #free, #initialize_copy, #inspect, #null?, #order, #read, #read_array_of_type, #read_string, #read_string_length, #read_string_to_null, size, #slice, #to_ptr, #to_s, #type_size, #write, #write_array_of_type, #write_string, #write_string_length
Methods inherited from AbstractMemory
#[], #__copy_from__, #clear, #freeze, #get, #get_array_of_float32, #get_array_of_float64, #get_array_of_pointer, #get_array_of_string, #get_bytes, #get_float32, #get_float64, #get_pointer, #get_string, #put, #put_array_of_float32, #put_array_of_float64, #put_array_of_pointer, #put_bytes, #put_float32, #put_float64, #put_pointer, #put_string, #read_array_of_double, #read_array_of_float, #read_array_of_pointer, #read_array_of_string, #read_bytes, #read_double, #read_float, #read_pointer, #size_limit?, #total, #type_size, #write_array_of_double, #write_array_of_float, #write_array_of_pointer, #write_bytes, #write_double, #write_float, #write_pointer
Constructor Details
#initialize(size, count = 1, clear = true) ⇒ self
A new instance of FFI::MemoryPointer.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'ext/ffi_c/MemoryPointer.c', line 89
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;
}
|
Class Method Details
.from_string(s) ⇒ MemoryPointer
Create a FFI::MemoryPointer with s
inside.
181 182 183 184 185 186 187 188 189 190 |
# File 'ext/ffi_c/MemoryPointer.c', line 181
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;
}
|