summaryrefslogtreecommitdiff
path: root/spec/ffi/pointer_spec.rb
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2023-03-06 18:19:47 +0100
committerJean Boussier <jean.boussier@gmail.com>2023-03-06 18:42:39 +0100
commiteebf52446fa627ad399d2cffeb103d2ff6254eaa (patch)
tree05382741ffaa4c81bc8e94c85cf4512a03a5cbbc /spec/ffi/pointer_spec.rb
parent3621607a0137cfda8ed36e1f04963a3326019f41 (diff)
downloadffi-eebf52446fa627ad399d2cffeb103d2ff6254eaa.tar.gz
Implement Write Barrier and dsize for FFI::Pointer
As well as FFI::MemoryPointer and FFI::AbstractMemory Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a dsize function so that these instance report a more relevant size in various memory profilers.
Diffstat (limited to 'spec/ffi/pointer_spec.rb')
-rw-r--r--spec/ffi/pointer_spec.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/spec/ffi/pointer_spec.rb b/spec/ffi/pointer_spec.rb
index 9c85da7..c8242c7 100644
--- a/spec/ffi/pointer_spec.rb
+++ b/spec/ffi/pointer_spec.rb
@@ -381,5 +381,13 @@ describe "AutoPointer" do
expect(mptr[1].read_uint).to eq(0xcafebabe)
end
end
+
+ it "has a memsize function", skip: RUBY_ENGINE != "ruby" do
+ base_size = ObjectSpace.memsize_of(Object.new)
+
+ pointer = FFI::Pointer.new(:int, 0xdeadbeef)
+ size = ObjectSpace.memsize_of(pointer)
+ expect(size).to be > base_size
+ end
end