I would like to allocate some byte buffers, to be passed to an external function, that have specific minimally aligned requirements.
The requirement is that the buffer be aligned to a N
-byte1 boundary, but not to a 2N
boundary. For example, if N
is 64, then an address p
should satisfy p % 64 == 0
and p % 128 != 0
.
Is there a reasonable way to do this with the standard facilities of C++11?
If not, is there is a reasonable way to do this outside the standard facilities2 which works in practice for modern compilers and platforms?
The buffer will be passed to an outside routine (adhering to the C ABI but written in asm). The required alignment will usually be greater than 16, but less than 8192.
1 As usual, N
is a power of two.
2 Yes, I understand an answer of this type causes language-lawyers to become apoplectic, so if that's you just ignore this part.
Aucun commentaire:
Enregistrer un commentaire