[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
RE: Copying an object
- From: Murray Cumming Comneon com
- To: rjshaw iprimus com au, gtk-app-devel-list gnome org
- Subject: RE: Copying an object
- Date: Sat, 25 Oct 2003 13:17:49 +0200
> From: gtk-app-devel-list-admin@gnome.org
> 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++?
Gobject are generally refcounted rather than copied. But there's probably
one or two that have clone() or copy() functions too.
There's also "boxed-types" that are just regular structs plus copy() and
free() functions. Look for g_boxed_type_register_static() in the source code
- in gdk_rectangle_get_type(), for instance. You still have to write the
code to do a deep copy, but you only have to write it once.
Murray Cumming
www.murrayc.com
murrayc@usa.net
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]