Subject:
[ruby-ffi] Re: How to copy a struct?
From:
Wayne Meissner
Date:
10/29/11 6:51 AM
To:
ruby-ffi@googlegroups.com

Or you could use Struct#dup.

e.g.  

$ ruby -rrubygems -e 'require "ffi"; class S < FFI::Struct; layout :a, :int; end; s1 = S.new; s1[:a] = 1234; s2 = s1.dup; puts "s1=#{s1.pointer.address}, s2=#{s2.pointer.address} s1[:a]=#{s1[:a]}, s2[:a]=#{s2[:a]}"'

s1=4311971984, s2=4312277120 s1[:a]=1234, s2[:a]=1234

Different memory addresses, same contents.