Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: another simple c question

Author: Anthony Cozzie

Date: 08:50:48 07/21/04

Go up one level in this thread


On July 21, 2004 at 06:34:18, Daniel Shawul wrote:

>On July 21, 2004 at 06:27:06, Paul Clarke wrote:
>
>>On July 21, 2004 at 06:16:10, Daniel Shawul wrote:
>>
>>>
>>>Isn't the size of a struct the sum of the sizes of its members.
>>>
>>>but for this struct sizeof(HASH_E) gives me 16 when i expect 14
>>>
>>>struct HASH_E
>>>{
>>>	HASHKEY checksum;
>>>	char     from;
>>>	char     to;
>>>	short    eval;
>>>	unsigned char    depth;
>>>	unsigned char    entry_threat_promote_seq;
>>>};
>>
>>Structures are padded so that their size is a multiple of the largest alignment
>>size required by any of the members. In this case that would be the HASHKEY
>>which, depending on your architecture, the compiler will probably want to align
>>on a four- or eight-byte boundary, so the compiler adds a couple of extra bytes
>>to make the structure a multiple of four or eight bytes. The idea is that, if
>>you have an array of these structs, all the fields in all the elements of the
>>array will have the required alignment.
>
>Thanks very much.
>I changed the "struct member alignment" to 1 byte. Previously it was
>8 byte. And now it displays the correct size 14.
>Is there any efficiecy loss by changing the alignment?? If there is any
>i don't want to do that?
>
>daniel

It is an extremely bad idea, because your struct (and worse, single variables
within the struct) could now lie across multiple cache lines.

anthony



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.