#pragma pack(L1_CACHE_LINE)
struct A {
//...
};
#pragma pack()
A a;
and
struct A {
//...
};
A a __attritube__((aligned(L1_CACHE_LINE)))
What’s difference between them?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The #pragma pack(byte-alignment) effect each member of the struct as specified by the byte-alignment input, or on their natural alignment boundary, whichever is less.
The
__attribute__((aligned(byte-alignment)))affect the minimum alignment of the variable (or struct field if specified within the struct)I believe the following are equivalent
where is A
a __attritube__((aligned(L1_CACHE_LINE)))will insureu_int32_t ainsidestruct Awill aligned with 2 byte but will not align the other variable in the same manner.Reference: