[NTLUG:Discuss] Processor architecture related queries
Vaidya, Harshal (Cognizant)
HarshalV at pun.COGNIZANT.COM
Wed Dec 3 04:39:19 CST 2003
Hi,
Till now I was well shielded from the system level world as I was predominantly working on web based systems. However, I am now working on a project which involves porting code from Solaris to Linux. I was reading up on the subject when I came across a topic related to padding and packing of structures.
It goes like this:
To achieve portable code it is specifically mentioned that the structures in C/C++ should be arranged in such a way that the objects having larger sizes should be placed prior to the objects having lower sizes. I would like to explain this taking an example.
Before porting:
Struct test
{
int height;
long width;
int weight;
{
Recommended for maximum portability:
Struct test
{
long width;
int height;
int weight;
}
The reason specified in the document I was reading is like this:
"If you put big and the highly aligned data objects in the front and put the less aligned objects toward the end, you will get better packing and higher efficiency in your structures. The reason is that the data can be found in the same cache line."
I am not able to make much sense the above line since I am not much aware of the "cache line" and "data padding or aligning" concepts. Could anybody please clarify this for me in breif detail. Even if any link is provided I'll be grateful enough.
_____
<< ella for Spam Control >> has removed 932 Spam messages and set aside 3 Newsletters for me
You can use it too - and it's FREE! www.ellaforspam.com
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: InterScan_Disclaimer.txt
Url: http://ntlug.org/pipermail/discuss/attachments/20031203/0547f136/InterScan_Disclaimer.txt
More information about the Discuss
mailing list