libpurple for non-gui clients

Will Thompson resiak at soc.pidgin.im
Thu Aug 9 08:46:56 EDT 2007


On Thu, Aug 09, 2007 at 03:18:44PM +0300, Kyryll A Mirnenko aka Mirya wrote:
> There's some sort of a problem using libpurple for non-ui clients: it creates 
> a conversation for every little talk. If a non-ui client handles lots of news 
> users it becomes a hazard.

By "hazard", do you mean "uses a tonne of memory"?  A PurpleConversation
is 44 bytes, a PurpleConvIm is 24 more, and the strings and hash tables
inside add up to, for one I have open now, about 150 more bytes.
Conservatively, four thousand conversations is about a megabyte of
memory.

>                            I've tried to destroy the conversation after a 
> message is sent _from_ my non-ui client, but that doesn't work for incoming 
> messages: I can't destroy the conversation itself in the write_conv() 
> callback (it results in the application crash).

The crash is presumably because write_conv is being called from some
function which will use the PurpleConversation struct again before
returning.  You could use an idle callback as follows:

    static gboolean
    idle_destroy_conversation_cb (gpointer data)
    {
        PurpleConversation *conv = (PurpleConversation *)data;
        purple_conversation_destroy (conv);
        return FALSE; /* don't keep calling this */
    }

    /* ... code scrolls by for a while ... */
    /* meanwhile, in your write_conv callback: */
        g_idle_add (idle_destroy_conversation_cb, conv);

See the documentation for g_idle_add.  If you're not using the glib
mainloop, your mainloop will presumably have some equivalent.  (Or you
could use purple_timeout_add (0, idle_destroy_conversation_cb, conv), I
guess.)

Will




More information about the Devel mailing list