why use STRUCTURE in C??

Hello All,

This question may not be related to NT. This question is about structures in
C.

Why should we use structures in C? I would like to know more in the context of
memeory utilization…

Thanks,
G!r!


This e-mail has been sent to you courtesy of OperaMail, as a free service from
Opera Software, makers of the award-winning Web Browser, Opera. Visit us at
http://www.opera.com/ or our portal at: http://www.myopera.com/ Your free e-mail
account is waiting at: http://www.operamail.com/


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Well,
Its like you ask why use C. Just from the top of my head:

  1. Communication protocols
  2. Data encapsulation
  3. DB
    Regards,
    Stas.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Girish Desai
Sent: Friday, April 27, 2001 7:56 PM
To: NT Developers Interest List
Subject: [ntdev] why use STRUCTURE in C??

Hello All,

This question may not be related to NT. This question is about structures in
C.

Why should we use structures in C? I would like to know more in the context
of
memeory utilization…

Thanks,
G!r!


This e-mail has been sent to you courtesy of OperaMail, as a free
service from
Opera Software, makers of the award-winning Web Browser, Opera. Visit us
at
http://www.opera.com/ or our portal at: http://www.myopera.com/ Your free
e-mail
account is waiting at: http://www.operamail.com/


You are currently subscribed to ntdev as: xxxxx@powernetsys.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Why do you think we SHOULD NOT use structures in C?

Gary

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Girish Desai
Sent: Friday, April 27, 2001 10:56 AM
To: NT Developers Interest List
Subject: [ntdev] why use STRUCTURE in C??

Hello All,

This question may not be related to NT. This question is about structures in
C.

Why should we use structures in C? I would like to know more in the context
of
memeory utilization…

Thanks,
G!r!


This e-mail has been sent to you courtesy of OperaMail, as a free
service from
Opera Software, makers of the award-winning Web Browser, Opera. Visit us
at
http://www.opera.com/ or our portal at: http://www.myopera.com/ Your free
e-mail
account is waiting at: http://www.operamail.com/


You are currently subscribed to ntdev as: xxxxx@delphieng.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I am at a loss for words…

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Girish Desai
Sent: Friday, April 27, 2001 10:56 AM
To: NT Developers Interest List
Subject: [ntdev] why use STRUCTURE in C??

Hello All,

This question may not be related to NT. This question is about
structures in
C.

Why should we use structures in C? I would like to know more in
the context of
memeory utilization…

Thanks,
G!r!


This e-mail has been sent to you courtesy of OperaMail, as a
free service from
Opera Software, makers of the award-winning Web Browser,
Opera. Visit us at
http://www.opera.com/ or our portal at: http://www.myopera.com/
Your free e-mail
account is waiting at: http://www.operamail.com/


You are currently subscribed to ntdev as: xxxxx@storagecraft.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Oh …

Because if you don’t use structures then you add the BASI back to the C and
end up with BASIC … and THAT is a terrible place to be!!!

Gary

-----Original Message-----
From: Jamey Kirby [mailto:xxxxx@storagecraft.com]
Sent: Sunday, April 29, 2001 10:30 AM
To: NT Developers Interest List
Subject: [ntdev] RE: why use STRUCTURE in C??

I am at a loss for words…

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Girish Desai
Sent: Friday, April 27, 2001 10:56 AM
To: NT Developers Interest List
Subject: [ntdev] why use STRUCTURE in C??

Hello All,

This question may not be related to NT. This question is about
structures in
C.

Why should we use structures in C? I would like to know more in
the context of
memeory utilization…

Thanks,
G!r!


This e-mail has been sent to you courtesy of OperaMail, as a
free service from
Opera Software, makers of the award-winning Web Browser,
Opera. Visit us at
http://www.opera.com/ or our portal at: http://www.myopera.com/
Your free e-mail
account is waiting at: http://www.operamail.com/


You are currently subscribed to ntdev as: xxxxx@storagecraft.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@delphieng.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hello All,

I understand the high level concept of strcutre. I heard that using structure
gives more efficient use of memory.

For example, If I declare char, int and char seperately, It may consume 32 bit
of memory as compiler tells us when we use sizeof. But internally it will
occupy more bytes, which is hidden to us by compiler or by OS. I am not sure
about this.

But if I declare the same thing is structure, like
struct ABC{ int
char
int
}
When we say, sizeof(ABC), it will be equal to size of( int+char+int). But
internally it will occupy less memory. Compiler or OS will do that job. My
question is, how does OS/compiler achieves this? My question is more related
to code optimization.

The enviornment here is x86 and NT. Compilers are again, any MS compilers…

Thanks,
G!r!

===== Original Message From Gary Little =====
>Oh …
>
>Because if you don’t use structures then you add the BASI back to the C and
>end up with BASIC … and THAT is a terrible place to be!!!
>
>Gary
>
>-----Original Message-----
>From: Jamey Kirby [mailto:xxxxx@storagecraft.com]
>Sent: Sunday, April 29, 2001 10:30 AM
>To: NT Developers Interest List
>Subject: [ntdev] RE: why use STRUCTURE in C??
>
>
>I am at a loss for words…
>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com]On Behalf Of Girish Desai
>> Sent: Friday, April 27, 2001 10:56 AM
>> To: NT Developers Interest List
>> Subject: [ntdev] why use STRUCTURE in C??
>>
>>
>> Hello All,
>>
>> This question may not be related to NT. This question is about
>> structures in
>> C.
>>
>> Why should we use structures in C? I would like to know more in
>> the context of
>> memeory utilization…
>>
>> Thanks,
>> G!r!
>>
>> ------------------------------------------------------------
>> This e-mail has been sent to you courtesy of OperaMail, as a
>> free service from
>> Opera Software, makers of the award-winning Web Browser,
>> Opera. Visit us at
>> http://www.opera.com/ or our portal at: http://www.myopera.com/
>> Your free e-mail
>> account is waiting at: http://www.operamail.com/
>> ------------------------------------------------------------
>>
>>
>> —
>> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
>> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>>
>
>—
>You are currently subscribed to ntdev as: xxxxx@delphieng.com
>To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@operamail.com
>To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

------------------------------------------------------------
This e-mail has been sent to you courtesy of OperaMail, as a free service from
Opera Software, makers of the award-winning Web Browser, Opera. Visit us at
http://www.opera.com/ or our portal at: http://www.myopera.com/ Your free e-mail
account is waiting at: http://www.operamail.com/
------------------------------------------------------------


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Actually, the amount of memory used by the structure in your example is determined
by the value of the “packing” set by the compiler options and modified by the
#pragma pack(x) statement. The default packing is 8 bytes, and indeed some APIs
used to actually fail (bugs in the headers) if you modified the packing default.
When considering packing, you should know that this can create unaligned data in
memory which can cause a performance hit when referencing that memory. On the x86
architecture I don’t think the hit is that bad (but it depends also on the
motherboard/chipset in use). On the IA64 architecture (and Alpha) the performance
impact of placing data on unaligned boundaries is HUGE (and can cause exceptions
in some cases).

Regards,

Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com

-----Original Message-----
From: Girish Desai [mailto:xxxxx@operamail.com]
Sent: Monday, April 30, 2001 9:55 AM
To: NT Developers Interest List
Subject: [ntdev] RE: why use STRUCTURE in C??

Hello All,

I understand the high level concept of strcutre. I heard that using structure
gives more efficient use of memory.

For example, If I declare char, int and char seperately, It may consume 32 bit
of memory as compiler tells us when we use sizeof. But internally it will
occupy more bytes, which is hidden to us by compiler or by OS. I am not sure
about this.

But if I declare the same thing is structure, like
struct ABC{ int
char
int
}
When we say, sizeof(ABC), it will be equal to size of( int+char+int). But
internally it will occupy less memory. Compiler or OS will do that job. My
question is, how does OS/compiler achieves this? My question is more related
to code optimization.

The enviornment here is x86 and NT. Compilers are again, any MS compilers…

Thanks,
G!r!

===== Original Message From Gary Little =====
>Oh …
>
>Because if you don’t use structures then you add the BASI back to the C and
>end up with BASIC … and THAT is a terrible place to be!!!
>
>Gary
>
>-----Original Message-----
>From: Jamey Kirby [mailto:xxxxx@storagecraft.com]
>Sent: Sunday, April 29, 2001 10:30 AM
>To: NT Developers Interest List
>Subject: [ntdev] RE: why use STRUCTURE in C??
>
>
>I am at a loss for words…
>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com]On Behalf Of Girish Desai
>> Sent: Friday, April 27, 2001 10:56 AM
>> To: NT Developers Interest List
>> Subject: [ntdev] why use STRUCTURE in C??
>>
>>
>> Hello All,
>>
>> This question may not be related to NT. This question is about
>> structures in
>> C.
>>
>> Why should we use structures in C? I would like to know more in
>> the context of
>> memeory utilization…
>>
>> Thanks,
>> G!r!
>>
>> ------------------------------------------------------------
>> This e-mail has been sent to you courtesy of OperaMail, as a
>> free service from
>> Opera Software, makers of the award-winning Web Browser,
>> Opera. Visit us at
>> http://www.opera.com/ or our portal at: http://www.myopera.com/
>> Your free e-mail
>> account is waiting at: http://www.operamail.com/
>> ------------------------------------------------------------
>>
>>
>> —
>> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
>> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>>
>
>—
>You are currently subscribed to ntdev as: xxxxx@delphieng.com
>To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@operamail.com
>To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

------------------------------------------------------------
This e-mail has been sent to you courtesy of OperaMail, as a free service
from
Opera Software, makers of the award-winning Web Browser, Opera. Visit us at
http://www.opera.com/ or our portal at: http://www.myopera.com/ Your free e-mail
account is waiting at: http://www.operamail.com/
------------------------------------------------------------


You are currently subscribed to ntdev as: xxxxx@ultrabac.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

If you don’t mind me asking, what are the conditions that can cause the
exceptions?

  • Shaun

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Paul Bunn
Sent: Monday, April 30, 2001 10:34 AM
To: NT Developers Interest List
Subject: [ntdev] RE: why use STRUCTURE in C??

Actually, the amount of memory used by the structure in your example is
determined
by the value of the “packing” set by the compiler options and modified by
the
#pragma pack(x) statement. The default packing is 8 bytes, and indeed some
APIs
used to actually fail (bugs in the headers) if you modified the packing
default.
When considering packing, you should know that this can create unaligned
data in
memory which can cause a performance hit when referencing that memory. On
the x86
architecture I don’t think the hit is that bad (but it depends also on the
motherboard/chipset in use). On the IA64 architecture (and Alpha) the
performance
impact of placing data on unaligned boundaries is HUGE (and can cause
exceptions
in some cases).

Regards,

Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com

-----Original Message-----
From: Girish Desai [mailto:xxxxx@operamail.com]
Sent: Monday, April 30, 2001 9:55 AM
To: NT Developers Interest List
Subject: [ntdev] RE: why use STRUCTURE in C??

Hello All,

I understand the high level concept of strcutre. I heard that using
structure
gives more efficient use of memory.

For example, If I declare char, int and char seperately, It may consume 32
bit
of memory as compiler tells us when we use sizeof. But internally it will
occupy more bytes, which is hidden to us by compiler or by OS. I am not sure
about this.

But if I declare the same thing is structure, like
struct ABC{ int
char
int
}
When we say, sizeof(ABC), it will be equal to size of( int+char+int). But
internally it will occupy less memory. Compiler or OS will do that job. My
question is, how does OS/compiler achieves this? My question is more related
to code optimization.

The enviornment here is x86 and NT. Compilers are again, any MS compilers…

Thanks,
G!r!

===== Original Message From Gary Little =====
>Oh …
>
>Because if you don’t use structures then you add the BASI back to the C and
>end up with BASIC … and THAT is a terrible place to be!!!
>
>Gary
>
>-----Original Message-----
>From: Jamey Kirby [mailto:xxxxx@storagecraft.com]
>Sent: Sunday, April 29, 2001 10:30 AM
>To: NT Developers Interest List
>Subject: [ntdev] RE: why use STRUCTURE in C??
>
>
>I am at a loss for words…
>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com]On Behalf Of Girish Desai
>> Sent: Friday, April 27, 2001 10:56 AM
>> To: NT Developers Interest List
>> Subject: [ntdev] why use STRUCTURE in C??
>>
>>
>> Hello All,
>>
>> This question may not be related to NT. This question is about
>> structures in
>> C.
>>
>> Why should we use structures in C? I would like to know more in
>> the context of
>> memeory utilization…
>>
>> Thanks,
>> G!r!
>>
>> ------------------------------------------------------------
>> This e-mail has been sent to you courtesy of OperaMail, as a
>> free service from
>> Opera Software, makers of the award-winning Web Browser,
>> Opera. Visit us at
>> http://www.opera.com/ or our portal at: http://www.myopera.com/
>> Your free e-mail
>> account is waiting at: http://www.operamail.com/
>> ------------------------------------------------------------
>>
>>
>> —
>> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
>> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>>
>
>—
>You are currently subscribed to ntdev as: xxxxx@delphieng.com
>To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@operamail.com
>To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

------------------------------------------------------------
This e-mail has been sent to you courtesy of OperaMail, as a free
service
from
Opera Software, makers of the award-winning Web Browser, Opera. Visit us
at
http://www.opera.com/ or our portal at: http://www.myopera.com/ Your free
e-mail
account is waiting at: http://www.operamail.com/
------------------------------------------------------------


You are currently subscribed to ntdev as: xxxxx@ultrabac.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@tenpennies.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Well,
Commenting on your sample:

  1. OS has nothing to do with structure sizes
  2. Compiler will make you ABC struct as big as all struct’s components + it
    will allign it to some custome byte boundary. (default value for VC is 8
    bytes allignment). You can change that for your whole project or just to one
    file or one struct with the “#pragma pack” directive. This stuff is very
    important to understand if one wishes to program communication protocols.
    Hope this helps,
    Stas,
    Powernet

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Girish Desai
Sent: Monday, April 30, 2001 6:55 PM
To: NT Developers Interest List
Subject: [ntdev] RE: why use STRUCTURE in C??

Hello All,

I understand the high level concept of strcutre. I heard that using
structure
gives more efficient use of memory.

For example, If I declare char, int and char seperately, It may consume 32
bit
of memory as compiler tells us when we use sizeof. But internally it will
occupy more bytes, which is hidden to us by compiler or by OS. I am not sure
about this.

But if I declare the same thing is structure, like
struct ABC{ int
char
int
}
When we say, sizeof(ABC), it will be equal to size of( int+char+int). But
internally it will occupy less memory. Compiler or OS will do that job. My
question is, how does OS/compiler achieves this? My question is more related
to code optimization.

The enviornment here is x86 and NT. Compilers are again, any MS compilers…

Thanks,
G!r!

===== Original Message From Gary Little =====
>Oh …
>
>Because if you don’t use structures then you add the BASI back to the C and
>end up with BASIC … and THAT is a terrible place to be!!!
>
>Gary
>
>-----Original Message-----
>From: Jamey Kirby [mailto:xxxxx@storagecraft.com]
>Sent: Sunday, April 29, 2001 10:30 AM
>To: NT Developers Interest List
>Subject: [ntdev] RE: why use STRUCTURE in C??
>
>
>I am at a loss for words…
>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com]On Behalf Of Girish Desai
>> Sent: Friday, April 27, 2001 10:56 AM
>> To: NT Developers Interest List
>> Subject: [ntdev] why use STRUCTURE in C??
>>
>>
>> Hello All,
>>
>> This question may not be related to NT. This question is about
>> structures in
>> C.
>>
>> Why should we use structures in C? I would like to know more in
>> the context of
>> memeory utilization…
>>
>> Thanks,
>> G!r!
>>
>> ------------------------------------------------------------
>> This e-mail has been sent to you courtesy of OperaMail, as a
>> free service from
>> Opera Software, makers of the award-winning Web Browser,
>> Opera. Visit us at
>> http://www.opera.com/ or our portal at: http://www.myopera.com/
>> Your free e-mail
>> account is waiting at: http://www.operamail.com/
>> ------------------------------------------------------------
>>
>>
>> —
>> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
>> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>>
>
>—
>You are currently subscribed to ntdev as: xxxxx@delphieng.com
>To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@operamail.com
>To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

------------------------------------------------------------
This e-mail has been sent to you courtesy of OperaMail, as a free
service from
Opera Software, makers of the award-winning Web Browser, Opera. Visit us
at
http://www.opera.com/ or our portal at: http://www.myopera.com/ Your free
e-mail
account is waiting at: http://www.operamail.com/
------------------------------------------------------------


You are currently subscribed to ntdev as: xxxxx@powernetsys.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Look at the documentation for SetErrorMode() specifically regarding the
SEM_NOALIGNMENTFAULTEXCEPT.

On Alpha, the performance cost for an alignment fixup is huge (and IA64 is reputed
to be as bad). The compiler provided the “__unaligned” keyword for pointers to
instruct the compiler to take the extra steps to load/store from a potentially
unaligned source. The code to do this is 3 times slower, but this is far less of
a hit than if the OS has to perform the fixups automatically.
For the worst performance possible on IA64/Alpha simply specify
SEM_NOALIGNMENTFAULTEXCEPT at process invocation, and make sure you have lots of
unaligned data.
As an example of what will cause an exception:

#pragma pack(1)
typedef struct {
char c;
long d;
} MYSTRUCT;
#pragma pack()

MYSTRUCT mystruct = (MYSTRUCT *) new char[sizeof(MYSTRUCT)];
mystruct->d = 23; // exception

Regards,

Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com

-----Original Message-----
From: Shaun Ruffell [mailto:xxxxx@tenpennies.com]
Sent: Monday, April 30, 2001 10:32 PM
To: NT Developers Interest List
Subject: [ntdev] RE: why use STRUCTURE in C??

If you don’t mind me asking, what are the conditions that can cause the
exceptions?

  • Shaun

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Paul Bunn
Sent: Monday, April 30, 2001 10:34 AM
To: NT Developers Interest List
Subject: [ntdev] RE: why use STRUCTURE in C??

Actually, the amount of memory used by the structure in your example is
determined
by the value of the “packing” set by the compiler options and modified by
the
#pragma pack(x) statement. The default packing is 8 bytes, and indeed some
APIs
used to actually fail (bugs in the headers) if you modified the packing
default.
When considering packing, you should know that this can create unaligned
data in
memory which can cause a performance hit when referencing that memory. On
the x86
architecture I don’t think the hit is that bad (but it depends also on the
motherboard/chipset in use). On the IA64 architecture (and Alpha) the
performance
impact of placing data on unaligned boundaries is HUGE (and can cause
exceptions
in some cases).

Regards,

Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com

-----Original Message-----
From: Girish Desai [mailto:xxxxx@operamail.com]
Sent: Monday, April 30, 2001 9:55 AM
To: NT Developers Interest List
Subject: [ntdev] RE: why use STRUCTURE in C??

Hello All,

I understand the high level concept of strcutre. I heard that using
structure
gives more efficient use of memory.

For example, If I declare char, int and char seperately, It may consume 32
bit
of memory as compiler tells us when we use sizeof. But internally it will
occupy more bytes, which is hidden to us by compiler or by OS. I am not sure
about this.

But if I declare the same thing is structure, like
struct ABC{ int
char
int
}
When we say, sizeof(ABC), it will be equal to size of( int+char+int). But
internally it will occupy less memory. Compiler or OS will do that job. My
question is, how does OS/compiler achieves this? My question is more related
to code optimization.

The enviornment here is x86 and NT. Compilers are again, any MS compilers…

Thanks,
G!r!

===== Original Message From Gary Little =====
>Oh …
>
>Because if you don’t use structures then you add the BASI back to the C and
>end up with BASIC … and THAT is a terrible place to be!!!
>
>Gary
>
>-----Original Message-----
>From: Jamey Kirby [mailto:xxxxx@storagecraft.com]
>Sent: Sunday, April 29, 2001 10:30 AM
>To: NT Developers Interest List
>Subject: [ntdev] RE: why use STRUCTURE in C??
>
>
>I am at a loss for words…
>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com]On Behalf Of Girish Desai
>> Sent: Friday, April 27, 2001 10:56 AM
>> To: NT Developers Interest List
>> Subject: [ntdev] why use STRUCTURE in C??
>>
>>
>> Hello All,
>>
>> This question may not be related to NT. This question is about
>> structures in
>> C.
>>
>> Why should we use structures in C? I would like to know more in
>> the context of
>> memeory utilization…


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

>

I understand the high level concept of strcutre. I heard that using
structure
gives more efficient use of memory.

For example, If I declare char, int and char seperately, It may consume 32
bit
of memory as compiler tells us when we use sizeof.

This is depends on Structure Alignment in Compiler Settings( Set Alignment
for 1 and try it ).

But internally it will
occupy more bytes, which is hidden to us by compiler or by OS. I am not
sure
about this.

Compiler.

But if I declare the same thing is structure, like
struct ABC{ int
char
int
}
When we say, sizeof(ABC), it will be equal to size of( int+char+int). But
internally it will occupy less memory.

It never occupy Less memory. Usually more memory based on alignment.

For More information. After writing the .C programm Dis-Assemble and check
it.

Regards,
Satish K.S


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com