Reputation: 485
I know what aligning a pointer means. I believe "size" here means the size of the memory to be occupied by the object in which the pointer is pointing to. But you're also given an "alignment" variable. What is the meaning of this variable? In this context, is it simply the value in which you want the address to be a multiple of? e.g., 4 (which I think is typical)?
Upvotes: 0
Views: 670
Reputation: 238311
In this context, is it simply the value in which you want the address to be a multiple of? e.g., 4
Yes.
And to align a pointer, you round the unaligned address up to the nearest multiple. There is a standard function for this purpose in the C++ standard library: std::align
. The function can also be used to test whether a pointer is aligned.
Upvotes: 1