在线文档教程
Ruby 2.4

Fiddle::CUnionEntity

class Fiddle::CUnionEntity

Parent:Fiddle::CStructEntity

一个C联合式包装

公共类方法

malloc(types, func=nil) Show source

为所提供的类型分配一个C联合。

当实例被废物收集时,C函数func被调用。

# File ext/fiddle/lib/fiddle/struct.rb, line 216 def CUnionEntity.malloc(types, func=nil) addr = Fiddle.malloc(CUnionEntity.size(types)) CUnionEntity.new(addr, types, func) end

size(types) Show source

返回与给定类型的联合所需的大小。

Fiddle::CUnionEntity.size( [ Fiddle::TYPE_DOUBLE, Fiddle::TYPE_INT, Fiddle::TYPE_CHAR, Fiddle::TYPE_VOIDP ]) #=> 8

# File ext/fiddle/lib/fiddle/struct.rb, line 228 def CUnionEntity.size(types) types.map { |type, count = 1| PackInfo::SIZE_MAP[type] * count }.max end

公共实例方法

set_ctypes(types) Show source

使用给定的类型计算每个联合成员的必要偏移量

# File ext/fiddle/lib/fiddle/struct.rb, line 236 def set_ctypes(types) @ctypes = types @offset = Array.new(types.length, 0) @size = self.class.size types end