Cheers every!
I want to store some data in memory in a structure, or in an array. My problem is data alignment. I cant really use a 8 byte data next to a char since they will take up 16 bytes together.
Now I would live happy with a single 8 byte field, like a char and using the remaining 7 bytes to store other data.
How do I do that? What are the performance penalties to pay?
Thanks people.
You can automate the bit shifting math suggested by Arkku with bitfields:
There will be slight access overhead but it’s worth it if you plan to use so many of these that space is at a premium. Over so much memory the improved cache locality will easily offset a few shift/mask operations.