Last active
January 29, 2021 06:04
-
-
Save kojix2/0cb7237d1bcfec2b613e47b094f6239c to your computer and use it in GitHub Desktop.
Ruby-FFIとFiddleによる構造体のclone時の挙動の違い
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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