Exporting shared data in C

Jannis Pohlmann info at sten-net.de
Fri Jul 28 10:09:42 CEST 2006


On Thu, 27 Jul 2006 17:56:48 -0700, Brian J. Tarricone wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 7/27/2006 5:45 PM, Jannis Pohlmann wrote:
> > Hi all,
> > 
> > as we were just talking about libfrapmenu/libxfce4menu, I'd like to
> > ask the more experienced people how I can export global data which
> > should be shared between client applications.
> > 
> > E.g., we have the root menu (/etc/xdg/menus/applications.menu)
> > which - once it's loaded - should be shared among all other
> > applications (e.g. a menu panel plugin and the appfinder).
> > Currently, the root menu is defined static inside the function
> > frap_menu_get_root:
> > 
> >   static FrapMenu* root = NULL;
> > 
> >   if (G_UNLIKELY (root == NULL))
> >     {
> >        ... load menu ...
> >     }
> > 
> >   return root;
> > 
> > Free'ing works by calling g_object_unref() on the returned object -
> > the last caller destroys the menu -, but at the moment all clients
> > perform the "... load menu ..." part. How can I avoid this?
> 
> What do you mean by "clients"?  Do you mean apps running in different
> processes?  If so, there isn't really any good way of doing this,
> aside from using sysv shared memory, or the X servers Xshm extension,
> or something like that.  Not sure why you need to do this...

Yes, apps using libfrapmenu. I thought probably would make sense
because there are a lot of desktop entries kept in memory and also the
whole root menu structure is kept after merging. I hoped that there is
a possibility for all apps to access the same data (which would then
need to be protected). But if there isn't, I'll just leave it as is.

> Otherwise, you could do something like write a 'menu daemon' which is
> a DBUS service, and applications who want to access the menu can
> request a tree from the daemon.  Sounds like pushing way too much
> data over DBUS, though.  And that doesn't seem to solve any problems
> - it makes it so the menu parsing only needs to be done once, but
> then you end up with a bunch of copies anyway.

No, D-BUS doesn't sound like a good solution. Neither does a daemon.

Regards,
Jannis



More information about the Xfce4-dev mailing list