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

Re: Memory woes



Rico wrote:
> 
> Hello All!
> I'm getting my hands dirrty with Pan. I have the following struct:
> ******************************************************************************
> typedef struct _Group
> {
>         GMutex       * article_mutex;
> 
>         guint          loaded_since_last_fetch  : 1;
>         guint          articles_dirty           : 1;
>         char           permission;
>         gint8          flags;
>         gint8          old_sort_style;
>         gint8          new_sort_style;
>         gulong         filter_show;
>         guint32        filter_bits;
>         gint32         article_qty;
>         gint32         article_read_qty;
>         gulong         article_low;
>         gulong         article_last_low_fetched;
>         gulong         article_high;
>         gulong         article_high_old;
> 
>         Server       * server;
>         char         * name;
>         char         * filter_name;
>         char         * identity_name;
>         char         * description;                      /* maybe null */
>         char         * download_dir;
>         char         * default_charset;
>         GStringChunk * chunk;
> 
>         /* PRIVATE */
>         int            _articles_refcount;
>         MemChunk     * _article_chunk;                   /* Article objects */
>         Newsrc       * _newsrc;
>         Newsrc       * _purged;
>         GHashTable   * _articles;
>         GPtrArray    * _deleted_articles;
>         char         * _one_big_chunk;
>         guint          _no_fetch_on_load        : 1;
> }
> Group;
> *****************************************************************************
> 
> Something like: Group * g = group_new(server, name);
> 
> returns a properly initialized, complete Group, with all the above members
> as reported by gdb. I add those Group's to a GPtrArray like so:
> 
>                 GPtrArray * groups = g_ptr_array_new ();
>                 g_ptr_array_add (groups, g);
> 
> then            call_some_func((Group **) groups->pdata);
> 
> but inside call_some_func(Group **groups), for all x, on
> 
>                 print *groups[x]
> 
> gdb does not see the last member, _no_fetch_on_load. However, the compiler does
> not complain about an unknown member. Instead,
> 
>        if (!groups[x]->_no_fetch_on_load) fetch_headers();
> 
> would _always_ make the call to fetch_headers(), even though I had set
> _no_fetch_on_load to TRUE before getting to that point. Anyone has any idea,
> could provide any hint about what's going on here? I've tried using a gboolean
> instead of a guint _no_fetch_on_load, but same problem. Also, what does the
> ':1'
> mean in "guint loaded_since_last_fetch : 1" ? Is it a compiler extension or is
> it standard C ?

`:1' is standard C.

it's usually used to keep structures small.
i.e. `:1' means this is a `1 bit' variable.

for example

struct structure {
	uint var1 : 2;
	uint var2 : 3;
	int  var3 : 1;
	uint var4 : 1;
	int  var5 : 25;
};

should yeild a structure
of 32 bits. (I think if they
total 8 bits it will still
total 32).


uint var: 1;
can hold the values 0 or 1.

uint var: 1 = -1; // what happens here ?

So what it comes down to is
the signed or unsigned bit.

if you assign TRUE to a
uint var:1; what do you
get ? (1 ?)

TRUE is usually defined as (!FALSE)
which is defined as (0).

printf("%d\n", TRUE); usually yeilds "-1"


anyhow... I'm sure you've got enough
information to proceed. (pretty cool
feature for the C compiler ;D )


Cheers,
		-Tristan

> 
> Thanks,
> Rico.
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Tax Center - forms, calculators, tips, more
> http://taxes.yahoo.com/
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



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