packing

Hi,
I have to write a given structure and sequence of
such structures to disk. I need to turn off packing
for this reason.

  1. How do I set packing as 0 just for this structure

  2. Am I limiting portability by doing this ?

Rajeev


Everything you always wanted to know about cars and bikes,now
at: http://in.autos.yahoo.com/cricket/tracker.html

Hi

#pragma pack(1) // set 1-byte packing

// Put your structures here

#pragma pack() // restore default packing

BR,
Vadim

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Rajeev Rao
Sent: Tuesday, May 14, 2002 4:01 AM
To: NT Developers Interest List
Subject: [ntdev] packing

Hi,
I have to write a given structure and sequence of
such structures to disk. I need to turn off packing
for this reason.

  1. How do I set packing as 0 just for this structure

  2. Am I limiting portability by doing this ?

Rajeev


Everything you always wanted to know about cars and bikes,now
at: http://in.autos.yahoo.com/cricket/tracker.html


You are currently subscribed to ntdev as: xxxxx@pcausa.com
To unsubscribe send a blank email to %%email.unsub%%

I prefer:

#include <pshpack1.h>
// Your structure
#include <poppack.h>

This is a tad more portable (since you implement the packing in a separate
.h file) plus the use of push/pop is safer with VC++ since it allows for the
case where the packing has already been set to something other than the
default.

/simgr

-----Original Message-----
From: Vadim V. Smirnov [mailto:xxxxx@pcausa.com]
Sent: Tuesday, May 14, 2002 6:24 PM
To: NT Developers Interest List
Subject: [ntdev] RE: packing

Hi

#pragma pack(1) // set 1-byte packing

// Put your structures here

#pragma pack() // restore default packing

BR,
Vadim

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Rajeev Rao
Sent: Tuesday, May 14, 2002 4:01 AM
To: NT Developers Interest List
Subject: [ntdev] packing

Hi,
I have to write a given structure and sequence of
such structures to disk. I need to turn off packing
for this reason.

1. How do I set packing as 0 just for this structure

2. Am I limiting portability by doing this ?

Rajeev

________________________________________________________________________
Everything you always wanted to know about cars and bikes,now
at: http://in.autos.yahoo.com/cricket/tracker.html


You are currently subscribed to ntdev as: xxxxx@pcausa.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to %%email.unsub%%</poppack.h></pshpack1.h>

#pragma push 1
structure def
#pragma pop

  1. no, not if this is the intended use of this data object.

-----Original Message-----
From: Rajeev Rao [mailto:xxxxx@yahoo.co.in]
Sent: Tuesday, May 14, 2002 7:01 AM
To: NT Developers Interest List
Subject: [ntdev] packing

Hi,
I have to write a given structure and sequence of
such structures to disk. I need to turn off packing
for this reason.

  1. How do I set packing as 0 just for this structure

  2. Am I limiting portability by doing this ?

Rajeev



Everything you always wanted to know about cars and bikes,now
at: http://in.autos.yahoo.com/cricket/tracker.html


You are currently subscribed to ntdev as:
xxxxx@stratus.com To unsubscribe send a blank email to
%%email.unsub%%

Note, you should align all your data members natuarally if at all possible. The reason for this is that moving data to/from unaligned destination causes a performance penalty. If you port to IA64 platform, the penalty is huge and would be a major concern if you are frequently moving to/from this structure. If you design a structure with natural alignment you get the bonus that you don’t have to use #pragma statements.

Regards,

Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - Windows NT/2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Tuesday, May 14, 2002 5:57 AM
To: NT Developers Interest List
Subject: [ntdev] RE: packing

#pragma push 1
structure def
#pragma pop

  1. no, not if this is the intended use of this data object.

-----Original Message-----
From: Rajeev Rao [mailto:xxxxx@yahoo.co.in]
Sent: Tuesday, May 14, 2002 7:01 AM
To: NT Developers Interest List
Subject: [ntdev] packing

Hi,
I have to write a given structure and sequence of
such structures to disk. I need to turn off packing
for this reason.

  1. How do I set packing as 0 just for this structure

  2. Am I limiting portability by doing this ?

Yes, but if the data structure is pre-defined, and does not conform to
the ‘natural alignment’, which happens a lot with embedded systems,
storage and network packet protocols, etc., you do have to use the
packing pragmas.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Paul Bunn
Sent: Tuesday, May 14, 2002 4:07 PM
To: NT Developers Interest List
Subject: [ntdev] RE: packing

Note, you should align all your data members natuarally if at
all possible. The reason for this is that moving data
to/from unaligned destination causes a performance penalty.
If you port to IA64 platform, the penalty is huge and would
be a major concern if you are frequently moving to/from this
structure. If you design a structure with natural alignment
you get the bonus that you don’t have to use #pragma statements.

Regards,

Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - Windows NT/2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Tuesday, May 14, 2002 5:57 AM
To: NT Developers Interest List
Subject: [ntdev] RE: packing

#pragma push 1
structure def
#pragma pop

  1. no, not if this is the intended use of this data object.

> -----Original Message-----
> From: Rajeev Rao [mailto:xxxxx@yahoo.co.in]
> Sent: Tuesday, May 14, 2002 7:01 AM
> To: NT Developers Interest List
> Subject: [ntdev] packing
>
>
> Hi,
> I have to write a given structure and sequence of
> such structures to disk. I need to turn off packing
> for this reason.
>
> 1. How do I set packing as 0 just for this structure
>
> 2. Am I limiting portability by doing this ?


You are currently subscribed to ntdev as:
xxxxx@hollistech.com To unsubscribe send a blank email to
%%email.unsub%%

Well, of course!

“Basil: Can’t we get you on Mastermind, Sybil? Next contestant Sybil Fawlty from Torquay, special subject stating the bleedin’ obvious.”

:wink:

-----Original Message-----
From: Mark Roddy [mailto:xxxxx@hollistech.com]
Sent: Tuesday, May 14, 2002 6:00 PM
To: NT Developers Interest List
Subject: [ntdev] RE: packing

Yes, but if the data structure is pre-defined, and does not conform to
the ‘natural alignment’, which happens a lot with embedded systems,
storage and network packet protocols, etc., you do have to use the
packing pragmas.

> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Paul Bunn
> Sent: Tuesday, May 14, 2002 4:07 PM
> To: NT Developers Interest List
> Subject: [ntdev] RE: packing
>
>
> Note, you should align all your data members natuarally if at
> all possible. The reason for this is that moving data
> to/from unaligned destination causes a performance penalty.
> If you port to IA64 platform, the penalty is huge and would
> be a major concern if you are frequently moving to/from this
> structure. If you design a structure with natural alignment
> you get the bonus that you don’t have to use #pragma statements.
>
> Regards,
>
> Paul Bunn, UltraBac Software, 425-644-6000
> Microsoft MVP - Windows NT/2000/XP
> http://www.ultrabac.com
>
>
> -----Original Message-----
> From: Roddy, Mark [mailto:xxxxx@stratus.com]
> Sent: Tuesday, May 14, 2002 5:57 AM
> To: NT Developers Interest List
> Subject: [ntdev] RE: packing
>
>
> 1)
> #pragma push 1
> structure def
> #pragma pop
>
> 2) no, not if this is the intended use of this data object.
>
> > -----Original Message-----
> > From: Rajeev Rao [mailto:xxxxx@yahoo.co.in]
> > Sent: Tuesday, May 14, 2002 7:01 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] packing
> >
> >
> > Hi,
> > I have to write a given structure and sequence of
> > such structures to disk. I need to turn off packing
> > for this reason.
> >
> > 1. How do I set packing as 0 just for this structure
> >
> > 2. Am I limiting portability by doing this ?

packing problems cannot be avoided for structures like

struct
{
LARGE_INTEGER,
LARGE_INTEGER,
INT
}

i would have made the last a LI too, but that would
waste too much diskspace. However I guess performance
wise this structure might not suffer a performance
penalty, when #pragma’s are used, as the padding is at
the end of the structure( after the int), provided of
course that the structures are not placed in an array,
forcing misalignment

Rajeev


Everything you always wanted to know about cars and bikes,now
at: http://in.autos.yahoo.com/cricket/tracker.html

It was bleedin’ obvious that “you should align all your data members natuarally if at all possible.”
----- Original Message -----
From: Paul Bunn
To: NT Developers Interest List
Sent: Tuesday, May 14, 2002 6:36 PM
Subject: [ntdev] RE: packing

Well, of course!

“Basil: Can’t we get you on Mastermind, Sybil? Next contestant Sybil Fawlty from Torquay, special subject stating the bleedin’ obvious.”

:wink:

-----Original Message-----
From: Mark Roddy [mailto:xxxxx@hollistech.com]
Sent: Tuesday, May 14, 2002 6:00 PM
To: NT Developers Interest List
Subject: [ntdev] RE: packing

Yes, but if the data structure is pre-defined, and does not conform to
the ‘natural alignment’, which happens a lot with embedded systems,
storage and network packet protocols, etc., you do have to use the
packing pragmas.

> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Paul Bunn
> Sent: Tuesday, May 14, 2002 4:07 PM
> To: NT Developers Interest List
> Subject: [ntdev] RE: packing
>
>
> Note, you should align all your data members natuarally if at
> all possible. The reason for this is that moving data
> to/from unaligned destination causes a performance penalty.
> If you port to IA64 platform, the penalty is huge and would
> be a major concern if you are frequently moving to/from this
> structure. If you design a structure with natural alignment
> you get the bonus that you don’t have to use #pragma statements.
>
> Regards,
>
> Paul Bunn, UltraBac Software, 425-644-6000
> Microsoft MVP - Windows NT/2000/XP
> http://www.ultrabac.com
>
>
> -----Original Message-----
> From: Roddy, Mark [mailto:xxxxx@stratus.com]
> Sent: Tuesday, May 14, 2002 5:57 AM
> To: NT Developers Interest List
> Subject: [ntdev] RE: packing
>
>
> 1)
> #pragma push 1
> structure def
> #pragma pop
>
> 2) no, not if this is the intended use of this data object.
>
> > -----Original Message-----
> > From: Rajeev Rao [mailto:xxxxx@yahoo.co.in]
> > Sent: Tuesday, May 14, 2002 7:01 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] packing
> >
> >
> > Hi,
> > I have to write a given structure and sequence of
> > such structures to disk. I need to turn off packing
> > for this reason.
> >
> > 1. How do I set packing as 0 just for this structure
> >
> > 2. Am I limiting portability by doing this ?


You are currently subscribed to ntdev as: xxxxx@acm.org
To unsubscribe send a blank email to %%email.unsub%%

To some, of course, especially to those high-priests over at the ACM. A quick examination of any code base of “real world” programs depressingly reveals that efficient design of structures is often overlooked, or not understood.

And, it should’ve been obvious to all but sufferers of a humor bypass operation that it was said in a lighthearted joking way, so chill already! :wink:

-----Original Message-----
From: Chris Pearson [mailto:xxxxx@acm.org]
Sent: Wednesday, May 15, 2002 7:46 PM
To: NT Developers Interest List
Subject: [ntdev] RE: packing

It was bleedin’ obvious that “you should align all your data members natuarally if at all possible.”
----- Original Message -----
From: Paul Bunn
To: NT Developers Interest List
Sent: Tuesday, May 14, 2002 6:36 PM
Subject: [ntdev] RE: packing

Well, of course!

“Basil: Can’t we get you on Mastermind, Sybil? Next contestant Sybil Fawlty from Torquay, special subject stating the bleedin’ obvious.”

:wink:

-----Original Message-----
From: Mark Roddy [mailto:xxxxx@hollistech.com]
Sent: Tuesday, May 14, 2002 6:00 PM
To: NT Developers Interest List
Subject: [ntdev] RE: packing

Yes, but if the data structure is pre-defined, and does not conform to
the ‘natural alignment’, which happens a lot with embedded systems,
storage and network packet protocols, etc., you do have to use the
packing pragmas.

> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Paul Bunn
> Sent: Tuesday, May 14, 2002 4:07 PM
> To: NT Developers Interest List
> Subject: [ntdev] RE: packing
>
>
> Note, you should align all your data members natuarally if at
> all possible. The reason for this is that moving data
> to/from unaligned destination causes a performance penalty.
> If you port to IA64 platform, the penalty is huge and would
> be a major concern if you are frequently moving to/from this
> structure. If you design a structure with natural alignment
> you get the bonus that you don’t have to use #pragma statements.
>
> Regards,
>
> Paul Bunn, UltraBac Software, 425-644-6000
> Microsoft MVP - Windows NT/2000/XP
> http://www.ultrabac.com
>
>
> -----Original Message-----
> From: Roddy, Mark [mailto:xxxxx@stratus.com]
> Sent: Tuesday, May 14, 2002 5:57 AM
> To: NT Developers Interest List
> Subject: [ntdev] RE: packing
>
>
> 1)
> #pragma push 1
> structure def
> #pragma pop
>
> 2) no, not if this is the intended use of this data object.
>
> > -----Original Message-----
> > From: Rajeev Rao [mailto:xxxxx@yahoo.co.in]
> > Sent: Tuesday, May 14, 2002 7:01 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] packing
> >
> >
> > Hi,
> > I have to write a given structure and sequence of
> > such structures to disk. I need to turn off packing
> > for this reason.
> >
> > 1. How do I set packing as 0 just for this structure
> >
> > 2. Am I limiting portability by doing this ?


You are currently subscribed to ntdev as: xxxxx@acm.org
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@ultrabac.com
To unsubscribe send a blank email to %%email.unsub%%

I took no offense, however if you had actually read the original query,
you might have observed that the fellow indeed had an external data
object problem that required a natural packing override solution.
Pontifications on the obvious benefits of not doing this were a bit
beside the point.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Paul Bunn
Sent: Thursday, May 16, 2002 1:23 AM
To: NT Developers Interest List
Subject: [ntdev] RE: packing

To some, of course, especially to those high-priests over at
the ACM. A quick examination of any code base of “real
world” programs depressingly reveals that efficient design of
structures is often overlooked, or not understood.

And, it should’ve been obvious to all but sufferers of a
humor bypass operation that it was said in a lighthearted
joking way, so chill already! :wink:

-----Original Message-----
From: Chris Pearson [mailto:xxxxx@acm.org]
Sent: Wednesday, May 15, 2002 7:46 PM
To: NT Developers Interest List
Subject: [ntdev] RE: packing

It was bleedin’ obvious that “you should align all your data
members natuarally if at all possible.”
----- Original Message -----
From: Paul Bunn
To: NT Developers Interest List
Sent: Tuesday, May 14, 2002 6:36 PM
Subject: [ntdev] RE: packing

Well, of course!

“Basil: Can’t we get you on Mastermind, Sybil? Next
contestant Sybil Fawlty from Torquay, special subject stating
the bleedin’ obvious.”

:wink:
>
>
> -----Original Message-----
> From: Mark Roddy [mailto:xxxxx@hollistech.com]
> Sent: Tuesday, May 14, 2002 6:00 PM
> To: NT Developers Interest List
> Subject: [ntdev] RE: packing
>
>
> Yes, but if the data structure is pre-defined, and does not
> conform to the ‘natural alignment’, which happens a lot with
> embedded systems, storage and network packet protocols, etc.,
> you do have to use the packing pragmas.
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Paul Bunn
> > Sent: Tuesday, May 14, 2002 4:07 PM
> > To: NT Developers Interest List
> > Subject: [ntdev] RE: packing
> >
> >
> > Note, you should align all your data members natuarally if at
> > all possible. The reason for this is that moving data
> > to/from unaligned destination causes a performance penalty.
> > If you port to IA64 platform, the penalty is huge and would
> > be a major concern if you are frequently moving to/from this
> > structure. If you design a structure with natural alignment
> > you get the bonus that you don’t have to use #pragma statements.
> >
> > Regards,
> >
> > Paul Bunn, UltraBac Software, 425-644-6000
> > Microsoft MVP - Windows NT/2000/XP
> > http://www.ultrabac.com
> >
> >
> > -----Original Message-----
> > From: Roddy, Mark [mailto:xxxxx@stratus.com]
> > Sent: Tuesday, May 14, 2002 5:57 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] RE: packing
> >
> >
> > 1)
> > #pragma push 1
> > structure def
> > #pragma pop
> >
> > 2) no, not if this is the intended use of this data object.
> >
> > > -----Original Message-----
> > > From: Rajeev Rao [mailto:xxxxx@yahoo.co.in]
> > > Sent: Tuesday, May 14, 2002 7:01 AM
> > > To: NT Developers Interest List
> > > Subject: [ntdev] packing
> > >
> > >
> > > Hi,
> > > I have to write a given structure and sequence of
> > > such structures to disk. I need to turn off packing
> > > for this reason.
> > >
> > > 1. How do I set packing as 0 just for this structure
> > >
> > > 2. Am I limiting portability by doing this ?
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@acm.org To unsubscribe send a blank email to
> %%email.unsub%%
> —
> You are currently subscribed to ntdev as: xxxxx@ultrabac.com
> To unsubscribe send a blank email to %%email.unsub%%
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@hollistech.com To unsubscribe send a blank email to
> %%email.unsub%%
>