Subject:
Re: [ruby-ffi] wiki update on pointers
From:
Jeremy Voorhis
Date:
5/11/10 12:01 PM
To:
ruby-ffi@googlegroups.com

It looks correct to me, except in my experience, MemoryPointer makes it unnecessary to wrap malloc(). For example, instead of,
  LibC.malloc(baz.first.size * baz.size)
I would write,
MemoryPointer.new(baz.first.size * baz.size).

The block form of MemoryPointer is also useful for automatically freeing the pointer when finished.

MemoryPointer.new(baz.first.size * baz.size) do |p|
p.write_array_of_int(baz)
C.DoSomethingWithArrayOfInt(p)
end

Best,

Jeremy

On Tue, May 11, 2010 at 9:02 AM, Chuck Remes <cremes.devlist@mac.com> wrote:
I just wrote an update to the wiki page on pointers at http://wiki.github.com/ffi/ffi/pointers

I'd appreciate it if someone more knowledgeable would check it over (the bottom section under the sub-heading) and verify that what I wrote is correct. It seems to be working for me but I've been wrong before! :)

cr