Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use _aligned_malloc()?

Tags:

c++

visual-c++

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.


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.

like image 768
최재훈 Avatar asked Sep 24 '08 06:09

최재훈


1 Answers

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.

like image 196
Viktor Avatar answered Sep 25 '22 17:09

Viktor