Method: DL::CStructEntity.size

Defined in:
lib/dl/struct.rb

.size(types) ⇒ Object

Given types, returns the offset for the packed sizes of those types

DL::CStructEntity.size([DL::TYPE_DOUBLE, DL::TYPE_INT, DL::TYPE_CHAR,
                        DL::TYPE_VOIDP])
=> 24


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/dl/struct.rb', line 95

def CStructEntity.size(types)
  offset = 0

  max_align = types.map { |type, count = 1|
    last_offset = offset

    align = PackInfo::ALIGN_MAP[type]
    offset = PackInfo.align(last_offset, align) +
             (PackInfo::SIZE_MAP[type] * count)

    align
  }.max

  PackInfo.align(offset, max_align)
end