Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] how to align the memory in c++ when passing in Struct

Status
Not open for further replies.

syedshan

Advanced Member level 1
Joined
Feb 27, 2012
Messages
463
Helped
27
Reputation
54
Reaction score
26
Trophy points
1,308
Location
Jeonju, South Korea
Activity points
5,134
hello every one,

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

Code:
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?

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


thanks
 

If I understood your question!!!!
You'll be passing the structured pointer instead of the char pointer so the issue is not there i.e. aligning the structure is not an issue. (Under no reasonable circumstances I can believe that you'll pass struct by value.)
You are just confused how you can have have malloc inside the struct. right?
Well, not an issue, just declare a char* inside the structure and initialize the structure before using it, the same way you did it in your previous code.
 

thanks for reply,


well I found one way to do so in VC++ uinsg _declspec() function


Code:
struct g_thread_param {
int thr_cnt ; 
int indv_cnt ;
__declspec(align(4096)) char mem_buff[XX];
} ;


Bests
Shan
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top