Skip to content

Instantly share code, notes, and snippets.

@kojix2
Last active January 29, 2021 06:04
Show Gist options
  • Save kojix2/0cb7237d1bcfec2b613e47b094f6239c to your computer and use it in GitHub Desktop.
Save kojix2/0cb7237d1bcfec2b613e47b094f6239c to your computer and use it in GitHub Desktop.
Ruby-FFIとFiddleによる構造体のclone時の挙動の違い
require 'ffi'
class S < FFI::Struct
layout :i, :int
end
a = S.new
a[:i] = 10
b = a.clone
b[:i] = 20
p a[:i] # 10
p b[:i] # 20
require 'fiddle/import'
S = Fiddle::Importer.struct(["int i"])
a = S.malloc
a.i = 10
b = a.clone
b.i = 20
p a.i # 20
p b.i # 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment