Memory alignment

Hi,
It may be an easy question, but I have many confusions about memory
alignment like 4byte align, 8 byte alinment or 32 byte alignment or say 4K
aligned … 1M aligned.

About 4b, 8b etc as I understand is that it should be multiple of 4 or
8byte boundary, but then how about 1MB aligned.
Once I allocate 1MB memory, how do I make it 1MB aligned.

thanks a lot in advance.
Raj


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

>About 4b, 8b etc as I understand is that it should be multiple of 4 or

8byte boundary, but then how about 1MB aligned.
Once I allocate 1MB memory, how do I make it 1MB aligned.

You can’t, either you have to use an allocation call that understands about
alignment, or else you allocate a chunk with the alignment size - 1 added
as padding and shift the starting address you use in the allocated block.
Of course this makes it tricky to deallocate, as you need to give the
original allocation address not your aligned address. Also note this gets
really inefficient if your alignment value is large relative to your chunk
size (i.e. allocating 64MByte aligned chunks of only 128 bytes).

Also note if your alignment size is large, the available addresses get’s
extremely restricted, for example there are not many chunks available that
are aligned on 256 MByte boundaries, like less that 8 (maybe a lot less
than 8).

  • Jan

You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com