tags:

views:

1150

answers:

4

I've been reading the legacy code,which invloves in the customized memory pooling system, then I found that the code uses _aligned_malloc. I wonder what is this function and when do I have to use it.

A: 

Have you checked the MSDN documentation? You can find the respective entry here.

Bjoern
+5  A: 

This function is useful when the alignment of your memory allocation is important to you. Alignment means that the numerical value of the pointer returned must be evenly divisible by a certain number, ie. ((unsigned int)ptr) % alignment should evaluate to 0.

An example of a reason for wanting a certain alignment is to use the data with the SSE instruction set on x86 where the data must be aligned to a multiple 16.

Viktor
Or you're trying to store 4 byte longs on a PowerPC (et al)
Andrew Edgecombe
+1  A: 

Thanks all of you.

I did read MSDN but what I wanted was the answer like "An example of a reason for wanting a certain alignment is to use the data with the SSE instruction set on x86 where the data must be aligned to a multiple 16".

I finally understood what those code means. thanks again.

최재훈
you might want to "accept" the answer then
Nathan Fellman
A: 

Another example - ARM processor. It requires to align all data to 4 bytes.

Igor Semenov