- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Structure size on VAX and ALPHA
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2005 11:07 PM
тАО08-03-2005 11:07 PM
typedef struct {
unsigned char length;
unsigned char l2;
char name[8];
int num;
} l_s_r;
I have the above declaration in a header file. and when i print the size of this structure
printf("Size of structure l_s_r is : %d",sizeof(l_s_r));
i get 2 different values on ALPHA and VAX-
On ALPHA the size is shown as - 16 bytes
ON VAX the size is shown as - 14 bytes
Interestingly the size of the below datatypes are same on both ALPHA and VAX.
unsigned char size is '1' byte
char size is '1' byte
int size is '4' byte
Then what could be reason for the difference in size of structure?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2005 11:31 PM
тАО08-03-2005 11:31 PM
Re: Structure size on VAX and ALPHA
alignment ?!
On Alpha, that int num will probably be naturally aligned, i.e. aligned to the next longword address.
Volker.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2005 11:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2005 11:47 PM
тАО08-03-2005 11:47 PM
Re: Structure size on VAX and ALPHA
I did not really get what you are saying. Could you pl elaborate? Also, what is the solution to overcome this problem, because instead of reading 14 bytes my structure is reading 16 bytes and so my file pointer is positioned at a wrong place.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2005 11:51 PM
тАО08-03-2005 11:51 PM
Re: Structure size on VAX and ALPHA
I agree with Volker. The alignment default in your two systems is different. Technically, to ensure that alignment is one way or the other, you need to use the #pragma [no]member_alignment C/C++ compiler directive.
Typically, this #pragma is used with state save/restore code, as follows:
#pragma member_alignment __save
#pragma [no]member_alignment
{ code defining structures }
#pragma member_alignment __restore
You need to save/restore the current settings because different source sets may have differing presumptions, for a wide variety of reasons. Saving/restoring the member_alignment state allows your structure to be defined as needed, without impacting the rest of the compilation.
For example, message formats for network messages are often packed by bytes, and use the nomember_alignment attribute. In memory data structures want the efficiency, and thus use the member_alignment attribute.
- Bob Gezelter, http://www.rlgsc.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2005 11:52 PM
тАО08-03-2005 11:52 PM
Re: Structure size on VAX and ALPHA
Marc seems to have answered this question already.
Please note that your code may pay a performance penalty, if you access data at non-aligned addresses. Sometimes the compiler can handle this, but sometimes it also happens at runtime, which is bad for performance on Alpha and really bad on Itanium (this is called alignment faults).
Volker.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-04-2005 01:00 AM
тАО08-04-2005 01:00 AM
Re: Structure size on VAX and ALPHA
Alpha and Itanium compilers will add padding bytes to structure members in order to align them on "natural" boundaries. So, your structure has 2 single characters, followed by an 8 character string. That's 10 bytes. The compiler adds 2 bytes of padding so the integer starts on a longword boundary (multiple of 4).
The VAX compiler does not align structure members by default.
So you have a choice if you want the VAX and Alpha compilers to both lay out your structure in memory identically. You can:
1) force the compiler to omit the pad bytes and place the members exactly where you want them - this can be specified with a qualifier "/NOMEMBER_ALIGNMENT" to affect ALL structures, or selectively with a pragma "#pragma member_alignment".
2) rearrange your fields so they will be aligned without having to pad anything
3) add your own padding
Accesses to unaligned data is more expensive than accessing aligned data on all three architectures. It's moderate on VAX, bad on Alpha and VERY bad on Itanium.
Bob and Marc have suggested option 1, but you may be better off rearranging the fields to:
typedef struct {
int num;
unsigned char length;
unsigned char l2;
char name[8];
} l_s_r;
So, the int is naturally aligned with no need for padding. General rule is to declare quads, followed by longs, followed by short ints, then character strings. Remember that for most code the order of fields and extra padding shouldn't matter (some, myself included, would argue that code that does depend on field order is fundamentally broken and should be fixed!)
If you're somehow stuck with a misaligned record in a data file, I recommend defining two structures - the on disk structure and the in-memory structure. Hide the misaligned structure in your file access layer and move the fields into the aligned structure for processing. Even better, write a program to convert all your files into an aligned structure layout.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-04-2005 06:59 PM
тАО08-04-2005 06:59 PM
Re: Structure size on VAX and ALPHA
2 observations -
1- rearranging the fields within the structure still returns me the wrong struct size. (returns me 16 bytes)
2- enclosing the structure between the #pragma directive works! (returns me 14 bytes)