From 3015a7aae7ddc9b63149df34b1f12366e07a9563 Mon Sep 17 00:00:00 2001 From: Chris Seaton Date: Tue, 19 May 2020 00:12:47 +0100 Subject: [ruby/fiddle] Improve documentation on how to correctly free memory and free memory in tests (#33) https://github.com/ruby/fiddle/commit/e59cfd708a --- ext/fiddle/lib/fiddle/struct.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'ext/fiddle/lib/fiddle') diff --git a/ext/fiddle/lib/fiddle/struct.rb b/ext/fiddle/lib/fiddle/struct.rb index 8a48a1cb8b..259903d25c 100644 --- a/ext/fiddle/lib/fiddle/struct.rb +++ b/ext/fiddle/lib/fiddle/struct.rb @@ -73,7 +73,12 @@ module Fiddle # # MyStruct = Fiddle::CStructBuilder.create(Fiddle::CUnion, types, members) # - # obj = MyStruct.allocate + # obj = MyStruct.malloc + # begin + # ... + # ensure + # Fiddle.free obj.to_ptr + # end # def create(klass, types, members) new_class = Class.new(klass){ @@ -112,7 +117,7 @@ module Fiddle # Allocates a C struct with the +types+ provided. # - # When the instance is garbage collected, the C function +func+ is called. + # See Fiddle::Pointer.malloc for memory management issues. def CStructEntity.malloc(types, func = nil) addr = Fiddle.malloc(CStructEntity.size(types)) CStructEntity.new(addr, types, func) @@ -267,7 +272,7 @@ module Fiddle # Allocates a C union the +types+ provided. # - # When the instance is garbage collected, the C function +func+ is called. + # See Fiddle::Pointer.malloc for memory management issues. def CUnionEntity.malloc(types, func=nil) addr = Fiddle.malloc(CUnionEntity.size(types)) CUnionEntity.new(addr, types, func) -- cgit v1.2.3