LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Data Alignment (https://www.linuxquestions.org/questions/programming-9/data-alignment-550243/)

nesta 04-30-2007 06:07 PM

Data Alignment
 
hi all,
i want to ask about what is data alignment exactly?
i google it but failed to find simple explanation ro this concept and its related problems.

so does anyone have an answer for this questions or an simple link that describes this problem?

thanks in advance.

theNbomr 04-30-2007 06:21 PM

In computer memory, each byte is stored and accessed in a linearly numbered range of addresses. When multiple bytes are used to make up a larger data type, such as integers, long integers, floating point types, and address types, the alignment of the multiple bytes within the address space may fall on boundaries that are or are not aligned with the storage size for that data type. For example, a 4-byte data type may start at an address that is an even multiple of 4, or not. Some/most/many CPU types are optimized to fetch a multi-byte word from a memory whose base address is a multiple of the size of that data. When a compiler/linker arranges the data segment components, it may or not arrange for the various data objects to be optimally aligned on addresses favorable to the particular CPU. It becomes a trade-off between speed and memory usage.
--- rod.

nesta 04-30-2007 06:35 PM

i really appreciate your answer but i want to know more about this data alignment so can u tell me about any link that explains data alignment simply.

thanks for your help

theNbomr 04-30-2007 06:41 PM

Its not a complex subject. My previous reply pretty much covers it. If you want nitty-gritty detail, you should look in the data books for the various CPUs that you are interested in &/or the manuals for whatever compiler(s) you want to use. Exactly what sort of information do you need?
--- rod.

nesta 04-30-2007 06:52 PM

actaully i have an arm-based processor board and the compiler i use is armcc and when i run my executable file on the hardware i got an error and i think this is because the unaligned data?
so i just want to know general information about data alignment then see what that arm processor specs and that armcc compiler options.

theNbomr 04-30-2007 07:14 PM

Okay, then you need to consult the reference manual for your Arm processor, and/or the C compiler documentation. If the board and compiler support a debugger such as gdb, then that may be a useful tool, as well.
--- rod.

Kristofer 05-01-2007 01:22 PM

Here is a link
 
This link might help, talks about ARM (XScale) alignment, the "problem" and possible solutions (including compiler flags).

http://lecs.cs.ucla.edu/wiki/index.php/XScale_alignment

/Kristofer


All times are GMT -5. The time now is 12:00 PM.