Skip to content

Commit 7e4cf34

Browse files
committed
Fixed memory management
1 parent 7d225eb commit 7e4cf34

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/thundersvm/model.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ def create_dataset(x, y = nil)
159159

160160
def str_ptr(arr)
161161
ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP * arr.size, Fiddle::RUBY_FREE)
162-
arr.each_with_index do |v, i|
163-
ptr[i * Fiddle::SIZEOF_VOIDP, Fiddle::SIZEOF_VOIDP] = Fiddle::Pointer["#{v}\x00"].ref
162+
str_ptrs = arr.map { |v| Fiddle::Pointer["#{v}\x00"] }
163+
str_ptrs.each_with_index do |v, i|
164+
ptr[i * Fiddle::SIZEOF_VOIDP, Fiddle::SIZEOF_VOIDP] = v.ref
164165
end
166+
ptr.instance_variable_set(:@thundersvm_refs, str_ptrs)
165167
ptr
166168
end
167169

0 commit comments

Comments
 (0)