Re: Copying an object



Russell Shaw wrote:
Hi,
I have C structs containing data and pointers to other objects and data.
It is like OOP in C. I need to make a copy of an object, but found it is
really tedious in C. The data in the struct can be copied, but you need
to recursively follow pointers, do a malloc, then copy the data that was
pointed at, into the new malloced area.

Is there an easy way to do it? Can g_object do it? C++?

On second thoughts, it is like the action of a C++ copy-constructor.

An N-ary tree can be copied because you know what each node is, so you know
which members are pointers to other nodes. However, if you want to copy a
tree of arbitrary type nodes at run-time, you need to find what node members
are pointers, so run-time "type" information is needed. I have lots of
pointers to small structs of various types, and it would seem to be a
fair bit of typing to convert them all to g_object things.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]