Re: glib g_array_sized_new problem



On Fri, 15 Jun 2001, Brian Cameron wrote:

>
> glib/gtk experts:
>
> When I call the glib function g_array_sized_new I was expecting that
> the array would be filled with NULL values since the 2nd argument
> (the "clear" argument) is set to TRUE.  Since I'm setting the size to
> 10, I was expecting the array to be full of 10 NULL array pointers.
>
>     my_array = g_array_sized_new (FALSE, TRUE,
>       sizeof(gchar *), 10);
>
> However, it doesn't work this way.  I have to then call this function
> to actually init the values to NULL:
>
>     g_array_set_size(obj->column_description, num_cols);
>
> Is this the way it is supposed to work?  I didn't find the docs very
> clear about this.

According to the glib documentation:

Creates a new #GArray with @reserved_size elements
preallocated. This avoids frequent reallocation, if you are going to
add many elements to the array. Note however that the size of the
array is still 0.

So the array starts out at size 0 still.  You will still need to append
your values to the array (but the first 10 appends won't result in any
realloc's of the array).

>
> You probably can already see this, but when I compile code that includes
> "gtk.h", I get these warnings (using the CVS head of today):
>
> /opt/gnome-2.0/include/gtk-2.0/gtk/gtkwindow.h:134:
>   warning: `GTK_WINDOW_GET_CLASS' redefined

Looks like this second definition should be GTK_WINDOW_GROUP_GET_CLASS.

> /opt/gnome-2.0/include/gtk-2.0/gtk/gtkwindow.h:47:
>    warning: this is the location of the previous definition

James.

-- 
Email: james daa com au
WWW:   http://www.daa.com.au/~james/






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