I'm working on this code where I want to create a 256-byte aligned vector. In my constructor, I have the following code:
BitVector(long bitSize) {
vector<long long> temp(bitSize, 0LL);
int size = sizeof(temp);
void* p2 = aligned_alloc(256, size);
void* p3 = memmove(p2, &temp, size);
vector<long long>* t = reinterpret_cast<vector<long long>*>(p3);
cout<<"t address: "<<t<<endl;
this->bits = *t;
cout<<"bits address: "<<&bits<<endl;
};
I'm not sure why, but the output is coming out like this:
t address: 0x55b8623fcf00
bits address: 0x7fff9c7fc6f0
I need to get the exact object from the pointer t, but accessing it by * isn't working.
I also tried storing a pointer to a vector in my class, but ran into issues where random values were being placed into the vector, so I've switched it to this implementation.
Is there a way to get the object from the pointer without changing the address?
More details on what I'm trying to do for clarification:
I'm building a Bloom filter, and I've found that storing long long objects is more efficient from memory than storing bits, so I'm changing single bits in each long long when I need to set a bit. However, for all of this memory optimization to be useful, I need my vector (or whatever storage mechanism) to be 256-byte aligned. I've finished implementing the rest of the Bloom filter methods, but I've been struggling on how to accomplish this alignment.