OK to hold on to DBusMessage?

Havoc Pennington hp at redhat.com
Sat May 14 09:43:22 PDT 2005


On Sat, 2005-05-14 at 12:37 -0400, Daniel B. Faken wrote:
> [I sent this a while ago but I guess no one is monitoring the 'messages 
> posted by non-subscribers' list]
> 

Yeah, I'm a terrible list moderator.

>   I was implementing some bindings and realized I could just use the 
> DBusMessage as an array type, only decoding it when its elements are 
> dereferenced.  To avoid copying..
>   Is this a bad idea?  Will keeping it around affect other objects (e.g. 
> keep them in memory)?

It shouldn't. The only reason I'd consider avoiding this is that it will
"leak" D-BUS throughout your code, when ideally in my mind the IPC
mechanism details are only found at the "edge" of a program.

Make sure you ref() the message though and unref() it when done.

>   How about having a way to add references to 
> individual elements (that is, the typed-values accessed by an iterator - 
> esp. container types)?

This wouldn't work - the message internally is just one huge malloc
block. It can only be freed (or not freed) as a whole.

Havoc




More information about the dbus mailing list