def memalign(cty, align):
"""Allocate a ctype object on the specific byte alignment
"""
# Allocate bytes with offset
mem = (c_uint8 * (sizeof(cty) + align))()
addr = addressof(mem)
# Move to alignment
offset = addr % align
if offset:
offset = align - offset
buf = cty.from_address(offset + addr)
assert 0 == addressof(buf) % align
return buf, mem
评论列表
文章目录