LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-30-2007, 07:07 PM   #1
nesta
Member
 
Registered: Aug 2006
Posts: 100

Rep: Reputation: 15
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.
 
Old 04-30-2007, 07:21 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
Old 04-30-2007, 07:35 PM   #3
nesta
Member
 
Registered: Aug 2006
Posts: 100

Original Poster
Rep: Reputation: 15
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
 
Old 04-30-2007, 07:41 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
Old 04-30-2007, 07:52 PM   #5
nesta
Member
 
Registered: Aug 2006
Posts: 100

Original Poster
Rep: Reputation: 15
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.
 
Old 04-30-2007, 08:14 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.

Last edited by theNbomr; 04-30-2007 at 08:15 PM.
 
Old 05-01-2007, 02:22 PM   #7
Kristofer
LQ Newbie
 
Registered: Nov 2005
Location: Sweden
Distribution: Slackware
Posts: 20

Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
memory alignment of a struct George2 Programming 4 04-04-2007 08:45 PM
Alignment of text in C pritchardtom Programming 3 11-21-2005 05:06 PM
about alignment eshwar_ind Programming 5 10-18-2004 09:27 AM
glabels alignment Spaz17 Linux - Software 1 11-28-2003 02:17 PM
Printer Alignment Looking_Lost Linux - Hardware 2 04-26-2003 09:50 AM


All times are GMT -5. The time now is 02:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration