Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c.moderated > #391
| From | George Neuner <gneuner2@comcast.net> |
|---|---|
| Newsgroups | comp.lang.c.moderated |
| Subject | Re: which one is faster? |
| Date | 2012-04-30 21:58 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <clcm-20120430-0006@plethora.net> (permalink) |
| References | <clcm-20120404-0002@plethora.net> <clcm-20120423-0005@plethora.net> |
On Mon, 23 Apr 2012 08:32:16 -0500 (CDT), Keith Thompson
<kst-u@mib.org> wrote:
>echo ma <fatmck@gmail.com> writes:
>> on a 32bit system.
>>
>> #pragma pack(4)
>> struct TestStruct
>> {
>> unsigned short a;
>> unsigned short b;
>> unsigned int c;
>> };
>> #pragma pack()
>> struct TestStruct t;
>> t.a = 0; //step 1
>> t.b = 1; //step 2
>> t.c = 2; //step 3
>>
>> Questing is : Are these 3 steps having the same perfomance time?
>
>Suppose you find out that one operation is faster than another on
>your system; what would you do with that information? If you need
>to assign a value to t.c, assigning a value to t.a might be faster,
>but that doesn't do yhou much good if it's not the right thing to do.
>
>(Note that "#pragma pack" is non-standard and potentially unsafe;
>see <http://stackoverflow.com/q/8568432/827263>. For your particular
>struct definition, it's unlikely to have any effect.)
The only real reasons for such tightly packed structures are to save
memory in *very* small systems, or to perform memory mapped device
access ... which brings up both coding issues such as register value
reuse and CPU/platform issues such as bus width, access alignment,
write-back caching, out-of-order execution, write combining, etc.
x86 being an exception, most 32-bit CPUs use memory mapped I/O
exclusively, and it often is desirable to create structures for
accessing groups of contiguous device "registers". However, in such
cases, making a single 32-bit access to A+B in order to write a 16-bit
value to B would be incorrect (and potentially destructive).
As someone else said already, it would be nice if the OP had given a
more complete description of the intended use.
George
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to comp.lang.c.moderated | Previous | Next — Previous in thread | Find similar | Unroll thread
which one is faster? echo ma <fatmck@gmail.com> - 2012-04-04 18:05 -0500
Re: which one is faster? James Kuyper <jameskuyper@verizon.net> - 2012-04-23 08:31 -0500
Re: which one is faster? "Joel C. Salomon" <joelcsalomon@gmail.com> - 2012-04-23 08:33 -0500
Re: which one is faster? David Brown <david@westcontrol.removethisbit.com> - 2012-04-23 08:33 -0500
Re: which one is faster? Thomas Richter <thor@math.tu-berlin.de> - 2012-04-23 08:31 -0500
Re: which one is faster? Keith Thompson <kst-u@mib.org> - 2012-04-30 21:57 -0500
Re: which one is faster? Barry Schwarz <schwarzb@dqel.com> - 2012-04-23 08:32 -0500
Re: which one is faster? Keith Thompson <kst-u@mib.org> - 2012-04-23 08:32 -0500
Re: which one is faster? George Neuner <gneuner2@comcast.net> - 2012-04-30 21:58 -0500
csiph-web