Author: Bruce Moreland
Date: 22:26:50 06/25/00
Go up one level in this thread
On June 25, 2000 at 22:48:44, Antonio Dieguez wrote:
>On June 25, 2000 at 21:58:06, Bruce Moreland wrote:
>
>>On June 25, 2000 at 20:43:53, Dann Corbit wrote:
>>
>>>malloc() it and your exe will be no bigger.
>>>It will still consume more memory when it runs, of course.
>
>in java I would not have to do that :(
>
>>Msvc would figure out that the array is all zeros, and not save it in the EXE.
>>It would get zapped up at run-time.
>>
>>That struct is 10 bytes long, which is a bad idea, since half the accesses on
>>the 32-bit value are going to be misaligned, which will kill you on some
>>architectures.
>>
>>bruce
>
>oops, yes am a total ignorant!, I thunk one long and three shorts are 14 bytes,
>can you tell me hoy many bytes are a long, and a short?
Typically 4 bytes for long and 2 for short. If you have a structure you deal
with a lot (which is the case with most structures in performance parts of chess
programs), you don't want to access a 32-bit quantity that's not on a 4-byte
boundary.
What this means is that if you have a 32-bit quantity in a structure, you want
to make sure that the size of the structure is divisible by four, and and that
it doesn't start at the wrong offset within the structure.
The compiler will try to help you sometimes, by automatically interting pad
bytes.
struct {
short x;
long y;
short z;
};
That's bad because you've got a long at offset 2. Your compiler might insert a
short before your long though, and another one after it, so sizeof this struct
might end up being 12.
struct {
short x;
short z;
long y;
};
That's better.
If you do this:
struct {
long x;
short y;
};
The compiler might pad this out to 8 bytes if you make an array of these. That
might be the right thing to do in this case anyway. In the case of a hash table
though, you should be thinking about what you really want to have happen, and
make sure the compiler is doing the right thing.
I think that it's better to stick the pad bytes in explicitly, if you know
exactly what you want.
On some architectures, having things aligned badly can cause a huge performance
penalty.
bruce
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.