copying pointers in structures [message #82602] |
Mon, 07 January 2013 09:27 |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
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
|
|
|