How (in C ++) to create a deep copy of a structure that contains member fields of type void** ?

  • Thread starter Thread starter Purple_Apple
  • Start date Start date
P

Purple_Apple

Guest
Hello. I need to create a deep copy of a structure containing fields of type void **. On the evening of April 3rd, I reread many posts on the StackOverflow. At first glance, there is a lot of information, but when start digging into the depths, then there is not so much that is required. Therefore, I decided to ask for help. I have a following structure:

// The pool of memory allocated for triangulation.
struct TriPool
{
// The first block of triangulated elements.
void** FirstBlock;
// The block from which the current selection of elements is performed.
void** CurrentAllocationBlock;
// Pointer to the next area of free memory for the item.
void* NextFreeMemorySlice;
// The header of a linked list representing a stack of elements
// from which memory has been freed.
void* TecnologyElementsStack;
// Pointer to the current block of elements in which triangulation is performed.
void** CurrentTriangulatedBlock;
// Pointer to the next triangulated element.
void* NextItemForTriangulation;
// Determines how new records will be aligned in memory.
int AlignBytes;
}

And I have an instance of this structure.

TriPool currentTriPool;

The fields of currentTriPool are assigned by values during the work of the application. At some point in the execution of the application, I need to make a deep copy of currentTriPool.

TriPool poolCopy;

And use pointer fields of poolCopy regardless of pointer fields of currentTriPool. Pointed values must also be copied. How to make such a deep copy? The use of pointers and pointed values in poolCopy should not interfere with the use of pointers and pointed values in currentTriPool. For example, I may need to set to NULL pointers in currentTriPool, but continue to use pointers and pointed values in poolCopy.
How to create such a deep copy?

Thank you in advance.

Continue reading...
 
Back
Top