I am trying to implement a defragmenter for preallocated memory. Suppose we have a void pointer with pre-allocated memory for sizeof(int) * 3:
void* ptr = operator new(sizeof(int) * 3);
And initialize the first and third pieces of memory
int *one = new (ptr) int(1);
int *three = new (ptr + sizeof(int) * 2) int(3);
And here is my question: is it possible to transfer the value from (ptr + sizeof(int) * 2)(* three) to the second position (ptr + sizeof(int))without knowing the type of value?
int *second = new (ptr + sizeof(int)) int(*three); not an option.
source
share