I have an array of templated structs, called a Block
:
using Block = std::array<T, SIZE>; // SIZE is a constant
I need to allocate memory for multiple Block
s, the number only known at run-time.
Each block is used by one thread. I wish to allocate the memory to prevent Block
/T
elements from straddling page and cache boundaries.
I found Linux's getpagesize()
but how can I allocate the memory to achieve the alignment?
I am unsure how to achieve the padding due to Block
using std::array
and the page size only being known at run-time.
This does not need to be portable, the code will only be ran on Linux.