2001-01-20 20:08:59 +00:00
|
|
|
Ownership of dynamic objects
|
|
|
|
----------------------------
|
|
|
|
|
2005-03-10 12:51:45 +00:00
|
|
|
Any object-oriented system or language that doesn't have automatic garbage
|
|
|
|
collection has many potential pitfalls as far as the pointers go. Therefore,
|
|
|
|
some standards must be adhered to as far as who owns what.
|
2001-01-20 20:08:59 +00:00
|
|
|
|
2005-03-10 12:51:45 +00:00
|
|
|
Strings
|
2010-11-01 13:32:43 +00:00
|
|
|
~~~~~~~
|
2005-03-10 12:51:45 +00:00
|
|
|
|
|
|
|
Arguments passed into a function are owned by the caller, and the function
|
|
|
|
will make a copy of the string for its own internal use. The string should
|
|
|
|
be const gchar *. Strings returned from a function are always a copy of the
|
Docs updates, clean up some headers.
Original commit message from CVS:
* docs/design/part-MT-refcounting.txt:
* docs/design/part-conventions.txt:
* docs/design/part-gstobject.txt:
* docs/design/part-relations.txt:
* docs/design/part-standards.txt:
* gst/gstbin.c: (gst_bin_add_func), (gst_bin_add),
(gst_bin_remove_func), (gst_bin_remove), (gst_bin_iterate_recurse),
(gst_bin_get_by_name), (gst_bin_get_by_interface),
(gst_bin_iterate_all_by_interface):
* gst/gstbuffer.h:
* gst/gstclock.h:
* gst/gstelement.c: (gst_element_class_init),
(gst_element_change_state), (gst_element_set_loop_function):
* gst/gstelement.h:
* gst/gstiterator.c:
* gst/gstobject.c: (gst_object_class_init), (gst_object_ref),
(gst_object_unref), (gst_object_sink), (gst_object_dispose),
(gst_object_dispatch_properties_changed), (gst_object_set_name),
(gst_object_set_parent), (gst_object_unparent),
(gst_object_check_uniqueness):
* gst/gstobject.h:
Docs updates, clean up some headers.
Free iterators in GstBin.
GstObject is now looking good.
2005-03-08 14:38:06 +00:00
|
|
|
original and should be freed after usage by the caller.
|
2001-01-20 20:08:59 +00:00
|
|
|
|
2005-03-10 12:51:45 +00:00
|
|
|
ex:
|
|
|
|
|
|
|
|
name = gst_element_get_name (element); /* copy of name is made */
|
|
|
|
.. use name ..
|
|
|
|
g_free (name); /* free after usage */
|
|
|
|
|
|
|
|
|
|
|
|
Objects
|
2010-11-01 13:32:43 +00:00
|
|
|
~~~~~~~
|
2005-03-10 12:51:45 +00:00
|
|
|
|
|
|
|
Objects passed into a function are owned by the caller, any additional
|
|
|
|
reference held to the object after leaving the function should increase the
|
|
|
|
refcount of that object.
|
|
|
|
|
|
|
|
Objects returned from a function are owned by the caller. This means that the
|
|
|
|
called should _free() or _unref() the object after usage.
|
|
|
|
|
|
|
|
ex:
|
|
|
|
|
|
|
|
peer = gst_pad_get_peer (pad); /* peer with increased refcount */
|
|
|
|
if (peer) {
|
|
|
|
.. use peer ..
|
|
|
|
gst_object_unref (GST_OBJECT (peer)); /* unref peer after usage */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Iterators
|
2010-11-01 13:32:43 +00:00
|
|
|
~~~~~~~~~
|
2005-03-10 12:51:45 +00:00
|
|
|
|
|
|
|
When retrieving multiple objects from an object an iterator should be used.
|
|
|
|
The iterator allows you to access the objects one after another while making
|
|
|
|
sure that the set of objects retrieved remains consistent.
|
|
|
|
|
|
|
|
Each object retrieved from an iterator has its refcount increased or is a
|
|
|
|
copy of the original. In any case the object should be unreffed or freed
|
|
|
|
after usage.
|
|
|
|
|
|
|
|
|
|
|
|
|