// This function returns a pointer less than 2 * alignment + or_mask bytes into the array. char* GetAlignedMemory(char* orig_ptr, size_t alignment, size_t or_mask) { if (!powerof2(alignment)) {
errx(1, "warning: alignment passed into GetAlignedMemory is not a power of two.");
} if (or_mask > alignment) {
errx(1, "warning: or_mask passed into GetAlignedMemory is too high.");
}
uintptr_t ptr = reinterpret_cast<uintptr_t>(orig_ptr); if (alignment > 0) { // When setting the alignment, set it to exactly the alignment chosen. // The pointer returned will be guaranteed not to be aligned to anything // more than that.
ptr += alignment - (ptr & (alignment - 1));
ptr |= alignment | or_mask;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.