Subject:
[ruby-ffi] Re: How to use native c-code's dynamic buffer pointer
From:
Wayne Meissner
Date:
3/11/12 5:59 PM
To:
ruby-ffi@googlegroups.com

I posted an answer on stackoverflow, but I'll repaste it here:

edit_db() takes a pointer to a pointer as its parameter, so you need something like:

db = LibDB.new_db()

# pack the 'db' pointer into a temporary bit of memory
dbp = FFI::MemoryPointer.new(:pointer)
dbp.write_pointer(db)

# equivalent of edit_db(&db);
LibDB.edit_db(dbp)

# read the 'db' pointer back out in case edit_db altered the actual pointer value
db = dbp.read_pointer


On Sunday, 11 March 2012 08:14:44 UTC+10, MJoutsi wrote:
Hi,

On c-code side it goes:

/* Declarations */
DATABLOCK *new_db ();
edit_db(DATABLOCK **db);

/* Usage */
db = new_db();
edit_db(&db);

How this goes on Ruby? https://github.com/ffi/ffi/wiki/Examples
mentions about MemoryPointer but on my case I already have that buffer
(created by new_db()), so how to pass reference to buffer for
edit_db() or how it should go?