add btAlignPointer template and use it in serializer/allocator

this should fix Issue 559
This commit is contained in:
erwin.coumans
2012-02-25 19:24:59 +00:00
parent 22dc2ca6c3
commit bafef09b6e
3 changed files with 26 additions and 26 deletions

View File

@@ -519,4 +519,21 @@ struct btTypedObject
return m_objectType;
}
};
///align a pointer to the provided alignment, upwards
template <typename T>T* btAlignPointer(T* unalignedPtr, size_t alignment)
{
union
{
T* ptr;
size_t integer;
};
const size_t bit_mask = ~(alignment - 1);
ptr = unalignedPtr;
integer += alignment-1;
integer &= bit_mask;
return ptr;
}
#endif //BT_SCALAR_H