I would like to initialize a vector of STRUfCT of size (128 bytes) with a non-trivial constructor with a reserved space (2^26). I would then like to ensure that each virtual page have an associated physical page.
I tried using memset but had error:
‘void* memset(void*, int, size_t)’ clearing an object of type ‘class std::vector<STRUCT>’ with no trivial copy-assignment; use assignment or value-initialization instead [-Werror=class-memaccess]
If it matters, I’ll be calling operator=(STRUCT const&) on each vector’s element to insert into the vector
I do not want to call the constructor of STRUCT since it does a lot more things, slowing down the startup.
I’ll be calling emplace_back on the vector to put STRUCT in the vector and I would like that to be as fast as possible.
Questions:
- Is “touching” memory a good idea for micro-optimization?
- If it is, what is a good way to achieve this? reinterpret_cast<void*>?
1