Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mempool: add some padding to ensure correct alignment #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

laarmen
Copy link
Contributor

@laarmen laarmen commented Jun 23, 2020

The _item_t structure is 64-bit aligned on 64-bit architectures, whereas
the allocated structures might very well be 32-bit aligned if, for
instance, they only hold integer values. This patch ensures that we
round up the size to a multiple of the natural alignment of the item
structure, thus ensuring that two consecutive items are properly
aligned.

Unaligned access to non-packed structures is undefined behavior.
On Intel processors, unaligned access can result in those accesses
being much slower than normal. On some other architectures, it could
simply crash the program :-).

Caveat: technically, the stdalign.h headers are part of C11

The _item_t structure is 64-bit aligned on 64-bit architectures, whereas
the allocated structures might very well be 32-bit aligned if, for
instance, they only hold integer values. This patch ensures that we
round up the size to a multiple of the natural alignement of the item
structure, thus ensuring that two consecutive items are properly
aligned.

Unaligned access to non-packed structures is undefined behaviour.
On Intel processors, unaligned access can result in those accesses
being much slower than normal. On some other architectures, it could
simply crash the program :-).

Signed-off-by: Simon Chopin <[email protected]>
@Neustradamus
Copy link

Dear @laarmen,

Can you open a PR at "good" place:

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants