Re: copying pointers in structures [message #82601] |
Mon, 07 January 2013 09:44 |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Monday, January 7, 2013 6:27:02 PM UTC+1, Helder wrote:
> Hi,
>
> I read some of the previous posts, but I think that I'm not using the right keywords or not understanding...
>
> Well, I have a structure that I would like to temporarily save to eventually restore later on. Now the problem is that when making a copy of a structure with pointers I only copy the reference and not the value, so restoring my values will not work.
>
> Is there a better/quicker way to do this:
>
> a = {data:ptr_new(10), number:0}
>
> b = a
>
> b.data = ptr_new(*a.data)
>
>
>
> This way, when I modify a.data with:
>
> *a.data = 0
>
> and want to restore it, I just use:
>
> a = b
>
> and a.data will now be again 10
>
>
>
> Is there a programmatic way to do this without knowing the content of the structure? A sort of deep_duplicate_structure or whatever?
>
>
>
> Thanks,
>
> Helder
Ok, ok, it seems like my search as come to a success... save and restore seem to do the work... I simply had to look for copying of objects instead of pointers.
Thanks anyway.
Cheers,
Helder
|
|
|