Problems with memcpy

Hey,
I have these two pointers and I want to copy pointer1 data to pointer2. I tried to use memcpy and it did what I wanted but when I accessed pointer2 outside of the method that I did The memcpy in it didn't contain pointer1 data. Below is code similar to the code that I used:

1
2
3
 CBaseInitBlock1 *pInitBlock1Saved = pSavedInitBlock1;// pointer1
 CBaseInitBlock1 *pInitBlock1New = pNewInitBlock1;//pointer2
 memcpy(&pInitBlock1New,&pInitBlock1Saved, sizeof(pInitBlock1Saved));


However, when doing the following pointer2 contained pointer1 data every time I accessed it:
 
*pInitBlock1New = *pInitBlock1Saved 


At this point I wanted to you what is the best way to execute what I am trying to accomplish.

Thanks In Advance
I do not think that you want to use memcpy().


The error ... pInitBlock1Saved is a variable. Somewhere in memory there is a block of memory (A) big enough to hold a pointer, i.e. a memory address. &pInitBlock1Saved is the location of that memory block.

The memory address that is stored in the memory refers to an another memory block (B) elsewhere.

memcpy(foo,&pInitBlock1Saved ... copy from location A ...

memcpy(foo,pInitBlock1Saved ... copy from location B ...

foo = *pInitBlock1Saved; ... copy from location B ...
So the second option is the best way to accomplish this?
You have not told us enough to answer that.

We do not know the properties of type CBaseInitBlock1, nor how complicated it is to copy assign.

We do not know whether the pointer points to single object, or to the beginning of an array of objects.

We do not know why you need to do deep copies.
Topic archived. No new replies allowed.