My question is composed of 2 parts.
- I noticed that memalign(block_size,bytes) on sparc(sun) with a cc compiler doesn't check that bytes is a power of 2 as opposed to memalign on intel linux and _aligned_malloc on windows with mvsc compiler that do check that bytes are a power of 2.
is this a bug in a sun, is there a patch or i need to write a memalign by my self.
Additionally i have a structure (not my code):
typedef struct CLHLockStruct { volatile CLHLockNode CACHE_ALIGN *Tail ; volatile CLHLockNode CACHE_ALIGN *MyNode[N_THREADS] ; volatile CLHLockNode CACHE_ALIGN *MyPred[N_THREADS] ; } CLHLockStruct;
I am compiling under MVSC (visual studio 2008):
CACHE_LINE_SIZE = 64
CACHE_ALIGN = __declspec(align(CACHE_LINE_SIZE))
N_THREADS = 8
sizeof(CLHLockStruct)=192
The code has been written initially for a sparc architecture, and i try to migrate it to MVSC without changing to much code.
in their code they use memalign(CACHE_LINE_SIZE,sizeof(CLHLockStruct)), and i have changed it to _aligned_malloc , my problem is that sizeof(CLHLockStruct) is not a power of 2, i may write some function that finds the next number that is a power of 2.
Is their a better approach ?
EDIT1
How may i padd this struct so that its size will be a power of 2?
EDIT2
Is there a function that acts like _aligned_malloc and malloc : returns a memory pointer aligned to the multiple of block_size but doesn't require the bytes to be a power of 2?