D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Fiddle
/
Pointer
/
Filename :
malloc-c.ri
back
Copy
U:RDoc::AnyMethod[iI"malloc:ETI"Fiddle::Pointer::malloc;TT:publico:RDoc::Markup::Document:@parts[ S:RDoc::Markup::Heading: leveli: textI" Examples;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"P# Automatically freeing the pointer when the block is exited - recommended ;TI"BFiddle::Pointer.malloc(size, Fiddle::RUBY_FREE) do |pointer| ;TI" ... ;TI" end ;TI" ;TI"G# Manually freeing but relying on the garbage collector otherwise ;TI"?pointer = Fiddle::Pointer.malloc(size, Fiddle::RUBY_FREE) ;TI" ... ;TI"pointer.call_free ;TI" ;TI"n# Relying on the garbage collector - may lead to unlimited memory allocated before freeing any, but safe ;TI"?pointer = Fiddle::Pointer.malloc(size, Fiddle::RUBY_FREE) ;TI" ... ;TI" ;TI"# Only manually freeing ;TI",pointer = Fiddle::Pointer.malloc(size) ;TI"begin ;TI" ... ;TI"ensure ;TI" Fiddle.free pointer ;TI" end ;TI" ;TI"n# No free function and no call to free - the native memory will leak if the pointer is garbage collected ;TI",pointer = Fiddle::Pointer.malloc(size) ;TI" ... ;T:@format0o:RDoc::Markup::Paragraph; [I"GAllocate +size+ bytes of memory and associate it with an optional ;TI"+freefunc+.;T@ o;; [I"QIf a block is supplied, the pointer will be yielded to the block instead of ;TI"Kbeing returned, and the return value of the block will be returned. A ;TI"/+freefunc+ must be supplied if a block is.;T@ o;; [ I"MIf a +freefunc+ is supplied it will be called once, when the pointer is ;TI"Kgarbage collected or when the block is left if a block is supplied or ;TI"Rwhen the user calls +call_free+, whichever happens first. +freefunc+ must be ;TI"Lan address pointing to a function or an instance of +Fiddle::Function+.;T: @fileI"ext/fiddle/pointer.c;T:0@omit_headings_from_table_of_contents_below00I"pointer;T[ I"(size, free = nil);TI")ext/fiddle/lib/fiddle/ffi_backend.rb;TFI"Pointer;TcRDoc::NormalClass00