Forum Discussion
using packet data types on nios
I am creating a large embedded file system on my board. Memory constraints may require that I use packed data types. I realize there are issues with data alignment and code efficiency, but maybe there are smarter ways to do it. I also need to xfer the file system data to/from a windows machine, and expect to have a translation module on the PC side.
There is a short discussion about this for the ARM processor here, and I wonder if the same basic rules apply to the Nios: http://www.arm.com/support/faqdev/1228.html (http://www.arm.com/support/faqdev/1228.html) By using __alignof__() and sizeof(), I can see the Nios compiler behavior is to pad in the same way as the ARM. So has anyone gone down this path before on the Nios and could give recommendations? Is it just a matter of declaring __packed structures and pointers, or is there more pain involved? thanks4 Replies
- Altera_Forum
Honored Contributor
"PACKED", not packet. I need an edit header function.
- Altera_Forum
Honored Contributor
i already had a problem with structure alignement,
see also http://forum.niosforum.com/forum/index.php...=findpost&p=776 (http://forum.niosforum.com/forum/index.php?showtopic=207&view=findpost&p=776) best regards - Altera_Forum
Honored Contributor
Thanks, this gives a good example. The problem you ran into is just one of several alignment issues. I don't think your structure was packed, so you only had to deal with the basic alignment between the buffer and the struct. You probably know that if you printed the address of each struct member, there would be some obvious padding.
In my filesystem, every field of every record will need to be packed for size efficiency, and there are lots of different types of records with different field sizes. Because of this I suspect half the non-byte types will end up unaligned, and so require unaligned access methods. I'd sure like to find out I am wrong. I am trying to determine if it is better to operate on a non-packed record and only pack/unpack on the actual write/read, or operate on the data directly. - Altera_Forum
Honored Contributor
I usually try to lump my odd-sized structure members together so the majority of the members are aligned.
It's really hard to know what the compiler will do, though, since it may well load your packed structure member into a register once and then not access the struct again. Probably best to start out packed, turn on full optimization and then fix performance problems. Andrew