Re: GList
- From: HuamiSoft Hubert Sokolowski <h sokolowski huamisoft com>
- To: gtk-app-devel-list gnome org
- Subject: Re: GList
- Date: Thu, 18 Aug 2005 09:51:34 +0200
Hi!
On Thu, 18 Aug 2005 00:52:45 -0500
Tristan Sloughter <kungfooguru gmail com> wrote:
I am using GLists and want to make sure I am freeing all the memory, and
not twice or course.
There are three possible functions for removing an element from the list:
g_list_remove (GList *list, gconstpointer data);
g_list_remove_link (GList *list, GList *llink);
g_list_delete_link (GList *list, GList *link_);
typedef struct {
gpointer data;
GList *next;
GList *prev;
} GList;
So, I want to be sure that /gpointer data/ is freed when I remove the
element from the list. If I call/ g_list_remove(...)/ will that take
care of freeing data? If so should I use glib allocating functions for
allocating the memory that /data/ points to, since it'll probably use
/g_free/ to free the /data/, or does it matter?
What is the difference between /remove_link/ and /delete_link/? If I
used /remove_link (...)/ I assume I'd have to free the memory pointed to
by /data/ on my own, that being the difference between /remove/ and
/remove_link/.
always when you allocate a memory, you need to free it by your self.
to free a list completely you need to free /data/ by your self if it
points to some memory that you allocated. g_list_remove removes an
element from a list and frees that element (but without freeing /data/).
g_list_remove_link removes an element without freeing it, but also sets
next and prev to NULL.
g_list_delete_link just removes an element without freeing it, but next
and prev still point where they were pointed.
I hope that it is clear :).
regards
--
HuamiSoft Hubert Sokolowski
http://www.huamisoft.com/
tel. (085) 7465779
kom. +48501456743
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]