Re: using typedef to create aligned types

"Brett Bibby" <[email protected]> Thu, 2 Dec 2004 08:52:41 +0800
Newsgroups gmane.games.devel.windows
Organization GameBrains
Message-ID <[email protected]>
Exactly, as I said it's only the start address.  If you have an array then 
it needs to be padded between each start address.

----- Original Message ----- 
From: "Andras Balogh" <[email protected]>
To: <[email protected]>
Sent: Thursday, December 02, 2004 8:30 AM
Subject: RE: [GD-Windows] using typedef to create aligned types


> Let Fred be:
>
> class Fred {
> public:
> int helloiamfred;
> };
>
> then sizeof(Fred) will be 4
>
> but if I align the same class to 16 bytes:
>
> class __declspec(align(16)) Fred {
> public:
> int helloiamfred;
> };
>
> then sizeof(Fred) will be 16!!!
>
> The reason is that if you want an array of Freds, each have to be aligned,
> so it's not just the base address, that's changed, but the padding too!
>
> Look here for more info and examples:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm
> /msmod_18.asp
>
>
>
> Andras
>
>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of
>> Brett Bibby
>> Sent: Wednesday, December 01, 2004 4:12 PM
>> To: [email protected]
>> Subject: Re: [GD-Windows] using typedef to create aligned types
>>
>> Not sure what kind of type Fred is, but Fred and Fred Aligned are the 
>> same
>> type, thus the same size.  They just _start_ at an aligned location in
>> RAM.
>> If Fred is a struct, your alignment doesn't say anything about the
>> alignment
>> of each element _within_ the struct.  If Fred is an element of a struct,
>> then that would effect the size of the struct it is contained within.
>>
>> If you are trying to align data within structs, it's better to pack them
>> nicely and align the struct start address than peppering code with
>> alignments everywhere.  There's a presentation about cache issues you
>> might
>> want to check out:
>>
>> http://www.gdconf.com/archives/2003/Ericson_Christer.ppt
>>
>> -Brett
>>
>> ----- Original Message -----
>> From: "Andras Balogh" <[email protected]>
>> To: <[email protected]>
>> Sent: Thursday, December 02, 2004 7:45 AM
>> Subject: [GD-Windows] using typedef to create aligned types
>>
>>
>> > MSDN says that I can use typedef to make aligned versions of my types,
>> eg:
>> >
>> > typedef __declspec(align(16)) Fred FredAligned16;
>> >
>> > This works when I declare variables, eg:
>> >
>> > Fred fred1;
>> > FredAligned16 fred2;
>> >
>> > fred2 is 16 bytes aligned, while fred1 is not
>> >
>> > But the strange thing is that sizeof(Fred) == sizeof(FredAligned16) is
>> > true,
>> > even though Fred's size is not a multiple of 16 bytes...
>> >
>> > When I declare different types (ie. not using typedef), then the sizeof
>> > will
>> > be different because the aligned type will be padded to the next
>> multiple
>> > of
>> > 16 bytes.
>> >
>> > Is this a bug in the compiler??
>> >
>> >
>> >
>> > Thanks,
>> >
>> > Andras
>> >
>> >
>> >
>> >
>> > -------------------------------------------------------
>> > SF email is sponsored by - The IT Product Guide
>> > Read honest & candid reviews on hundreds of IT Products from real 
>> > users.
>> > Discover which products truly live up to the hype. Start reading now.
>> > http://productguide.itmanagersjournal.com/
>> > _______________________________________________
>> > Gamedevlists-windows mailing list
>> > [email protected]
>> > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
>> > Archives:
>> > http://sourceforge.net/mailarchive/forum.php?forum_id=555
>> >
>>
>>
>>
>> -------------------------------------------------------
>> SF email is sponsored by - The IT Product Guide
>> Read honest & candid reviews on hundreds of IT Products from real users.
>> Discover which products truly live up to the hype. Start reading now.
>> http://productguide.itmanagersjournal.com/
>> _______________________________________________
>> Gamedevlists-windows mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
>> Archives:
>> http://sourceforge.net/mailarchive/forum.php?forum_id=555
>
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://productguide.itmanagersjournal.com/
> _______________________________________________
> Gamedevlists-windows mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
> Archives:
> http://sourceforge.net/mailarchive/forum.php?forum_id=555 



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=555