本文整理匯總了Python中ctypes.alignment方法的典型用法代碼示例。如果您正苦於以下問題:Python ctypes.alignment方法的具體用法?Python ctypes.alignment怎麽用?Python ctypes.alignment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ctypes
的用法示例。
在下文中一共展示了ctypes.alignment方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _from_ctypes_structure
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import alignment [as 別名]
def _from_ctypes_structure(t):
for item in t._fields_:
if len(item) > 2:
raise TypeError(
"ctypes bitfields have no dtype equivalent")
if hasattr(t, "_pack_"):
formats = []
offsets = []
names = []
current_offset = 0
for fname, ftyp in t._fields_:
names.append(fname)
formats.append(dtype_from_ctypes_type(ftyp))
# Each type has a default offset, this is platform dependent for some types.
effective_pack = min(t._pack_, ctypes.alignment(ftyp))
current_offset = ((current_offset + effective_pack - 1) // effective_pack) * effective_pack
offsets.append(current_offset)
current_offset += ctypes.sizeof(ftyp)
return np.dtype(dict(
formats=formats,
offsets=offsets,
names=names,
itemsize=ctypes.sizeof(t)))
else:
fields = []
for fname, ftyp in t._fields_:
fields.append((fname, dtype_from_ctypes_type(ftyp)))
# by default, ctypes structs are aligned
return np.dtype(fields, align=True)
示例2: _alignment
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import alignment [as 別名]
def _alignment(cls):
return ctypes.alignment(cls._ctype)