Ruby-FFI provides wrappers for data structures generated on the heap to be accessed like Ruby objects. In particular,automatically generated accessor functions provide read/write access to data structure members. This implies that, with care, data structures can remain in their native binary form without translation. This can provide a performance advantage when calling library functions serially but has the potential for a large performance penalty if a variable is repeatedly translated between native and Ruby data types, particularly if the translation occurs transparently without specific input from the user. The disadvantage in dealing with library native objects is that they fall outside the purview of Ruby’s garbage collection system, and the destruction of objects must be handled carefully. In many cases this can be ameliorated
by immediately associating each heap variable with a Ruby stack object. On destruction of the stack object, a destructor functionality can release the associated heap variable.