[osg-users] How to byte-align Vec4Array
David Spilling
david.spilling at gmail.com
Tue Jul 8 06:13:28 PDT 2008
Hi Gordon, Thibault,
Thanks for the replies regarding the contiguity of the memory in a
std::vector. That at least solves half of the problem.
>
> Use &yourvector[0] to get a float* pointer to the beginning of the
> array.
How do I define the vec4array so that &yourvector[0] is absolutely aligned,
i.e. a multiple of (in my case) 16?
With a float array, on MS compilers, I would do __declspec(align(16)) float*
myarray = new float[4 * MY_ARRAY_SIZE]. From what I understand, and from the
MSDN documentation (http://msdn.microsoft.com/en-us/library/83ythb65.aspx)
this is the correct way to guarantee this. #pragma pack 16 doesn't always do
what you expect...
If I do __declspec(align(16)) Vec4Array* myarray = new Vec4Array, I'm
guaranteed that "myarray" is 16 byte aligned, but what about the contents of
the array? Especially if I do lots of ->push_back so that the std::vector
resizes and goes somewhere else. Even if I do __declspec(align(16))
Vec4Array* myarary = new Vec4Array(MY_ARRAY_SIZE) I don't think I'm
guaranteed 16 byte alignment of the first vector entry...
(I think the gcc equivalent to __declspec(align(X)) is __aligned__(X), by
the way).
Regards,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080708/2ec126f9/attachment-0003.htm>
More information about the osg-users
mailing list