Skip to main content
GameDev.net gamedev.net
🔒 Locked

Memory Alignment

Started by MicahJon Nov 20, 2000 at 4:00 PM 6 replies 700+ views
Original Post
MicahJon
MicahJon
My compiler has four settings for memory alignment (8, 16, 32, 64 bits). Which one is preferred, 32 or 64? Thanks, Micah
MicahJon
MicahJon
Sorry Mike,

I should have mentioned this is for a 32bit Windows compiled for Pentium class machines. The default config for memory alignment for my compiler (Borland C++ 5.02) is byte. I would hope that you would agree that this is not a good choice.

So again I ask, (more clearly this time) what is the preferred memory alignment for Win32 apps on Pentium class machines, 32 or 64?

Micah
snowmoon
snowmoon
You will have to test your program to see what is best. Sometime 32 bit alignment will result in faster reads and writes from memory, but it also increases your binary size because you are padding some vairables. This additional size might be enough to push your core program out of CPU cache therefore making it slower that the byte aligned variables.

So as you can see it depends on the program. If it makes no diffrence leave it alone.
Serge K
Serge K
You should always use largest size for memory alignment.
In case of VC6 - 8 byte is enough (it has no intrinsic datatypes large then 64bit).
For Intel C++ compiler - 16 bytes (if you want to use SSE).

If you think, that because of the alignment you wasting too much memory - just rearrange members in the critical structures & classes.
NuffSaid
NuffSaid
quote:
Original post by Serge K

You should always use largest size for memory alignment.
In case of VC6 - 8 byte is enough (it has no intrinsic datatypes large then 64bit).
For Intel C++ compiler - 16 bytes (if you want to use SSE).

If you think, that because of the alignment you wasting too much memory - just rearrange members in the critical structures & classes.


I don't understand that. Why must you always use the largest size for memory alignment? I thought that the current crop of processors were 32 bit, therefore the optimum alignment would be 4 bytes. 8 bytes would only be necessary if you were intending to have your programs ported to a 64 bit OS (sometime in the future).

Or am I mistaken? Any clarifications will be appreciated.







Edited by - NuffSaid on December 2, 2000 5:24:53 AM
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Serge K
Serge K
quote:
Original post by NuffSaid

I thought that the current crop of processors were 32 bit, therefore the optimum alignment would be 4 bytes. 8 bytes would only be necessary if you were intending to have your programs ported to a 64 bit OS (sometime in the future).



You forgot about double.
Also you need 64bit alignment for MMX.
And you must use 128bit alignment with SSE.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.