Class: RbSDL2::RefCountPointer

Inherits:
FFI::AutoPointer
  • Object
show all
Defined in:
lib/rb_sdl2/ref_count_pointer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.entity_classObject

Raises:

  • (NotImplementedError)


4
5
6
# File 'lib/rb_sdl2/ref_count_pointer.rb', line 4

def entity_class
  raise NotImplementedError
end

.to_ptr(ptr) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
# File 'lib/rb_sdl2/ref_count_pointer.rb', line 8

def to_ptr(ptr)
  raise ArgumentError, 'Invalid pointer, ptr is NULL' if ptr.null?
  # refcount の増加を AutoPointer 化する前に成功させる必要がある。
  # AutoPointer になった後に失敗すると、GC に回収されたとき refcount が実際の参照数より少なくなる。
  entity_class.new(ptr)[:refcount] += 1
  new(ptr)
end

Instance Method Details

#refcountObject

for debug



18
# File 'lib/rb_sdl2/ref_count_pointer.rb', line 18

def refcount = self.class.entity_class.new(self)[:refcount]