glib: problem with GArray

E

Erwan Loisant

Hello.

I can't properly add elements to a GArray. Basically I have a GArray
of GList, so here is what I do to append an element in a given GList
of my GArray:

1. GList* currentBucket = g_array_index (buckets, GList*, index);
2. currentBucket = g_list_append(currentBucket, node);
3. g_array_insert_val(buckets, index, currentBucket);


1) Get the GList* at the "index" position
2) Append the "node" element in my GList
3) Put back the pointer to GList in the GArray (I think it is needed
especially for the first insertion, since currentBucket is NULL).

The problem is, each time I try to insert a new element, the
"currentBucket" that I get is NULL. For the first insertion at a given
level it's ok, but after that I am supposed to receive a non-null
GList.

Can you see what is the problem?
 
J

Joona I Palaste

Erwan Loisant <[email protected]> scribbled the following
I can't properly add elements to a GArray. Basically I have a GArray
of GList, so here is what I do to append an element in a given GList
of my GArray:

Please ask platform-specific questions on platform-specific
newsgroups, thanks.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"And according to Occam's Toothbrush, we only need to optimise the most frequent
instructions."
- Teemu Kerola
 
R

Richard Bos

I can't properly add elements to a GArray. Basically I have a GArray
of GList, so here is what I do to append an element in a given GList
of my GArray:
Can you see what is the problem?

Yes. The problem is that neither GArray (Who he? A glamrock singer?) and
GList (The Wicked Witch of the Nor'norwest?) are part of ISO C, so this
question cannot possibly be answered reliably in comp.lang.c unless you
provide us with their definitions.

Richard
 
L

Larry I Smith

Erwan said:
Hello.

I can't properly add elements to a GArray. Basically I have a GArray
of GList, so here is what I do to append an element in a given GList
of my GArray:

1. GList* currentBucket = g_array_index (buckets, GList*, index);
2. currentBucket = g_list_append(currentBucket, node);
3. g_array_insert_val(buckets, index, currentBucket);


1) Get the GList* at the "index" position
2) Append the "node" element in my GList
3) Put back the pointer to GList in the GArray (I think it is needed
especially for the first insertion, since currentBucket is NULL).

The problem is, each time I try to insert a new element, the
"currentBucket" that I get is NULL. For the first insertion at a given
level it's ok, but after that I am supposed to receive a non-null
GList.

Can you see what is the problem?

Try the GTK mailing lists found at:

http://www.gtk.org

or the GNOME mailing lists found at:

http://www.gnome.org

Regards,
Larry
 
E

Erwan Loisant

Thank you.

I finally found what was the problem. "g_array_insert_val" actually
inserts the element while I thought it replaced the existing one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top