Question

My need is to aligned the memory by 4096, since this is the requirement of the dll I am using. so previously it was no problem since just I used to have

char *mem_buff = (char *)_aligned_malloc(sizeof(char)*XX, 4096);

but now since I want to share the memory using struct (for the reason of using the threads) hence I am stuck with what and how to do?

struct g_thread_param {
int thr_cnt ; 
int indv_cnt ;
char mem_buff[XX]; //what to do to aligne this to 4096
} ;

thanks

Était-ce utile?

La solution

If this is a DLL and you are compiling with MSVC / Visual C++, you can explicitly align the struct members:

struct g_thread_param {
int thr_cnt ; 
int indv_cnt ;
__declspec(align(4096)) char mem_buff[XX];
} ;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top