Re: gtk-app-devel-list digest, Vol 1 #592 - 5 msgs



On Wed, 2001-08-29 at 16:04, Alberto Cabello Sánchez wrote:
Hi, 

What about memory? Does GTK allocates (new) memory for this chars
pointed by my_text? From the other hand: do I have to free memory
pointed by my_text after using it??

It looks like GTK to allocate memory at his own risk, because you have to
free it when you finish you application (well, a bit before this).

GTK+ allocates new memory for the string, yes, and you need to free it.

You can
just try it without malloc, and if you don't get a segfault, it was true.

hmm...this isn't really the way to test these things, you know.  ;)
It is not dependable in any way, since we are talking about freeing
something that the runtime system may or may not reclaim immediatly, so
rather than an immediate response in form of a segfault you are likely
to get a segfault at some later time, in some completely different part
of the program, or worse yet, you get no segfault, but the program does
something completely unexpected, because you have messed with its
memory.  Never a nice thing to do to a poor innocent program.

And with the source available, there isn't really any need to *test* for
this, just read the code for the function.  You will notice a call to
g_strdup which will tell you all you need to know.  (Assuming that you
know what g_strdup does, but I think this function is fairly well
documented).

        /mailund

-- 
Think of hummingbirds as the flying penises of flowers

Attachment: pgpwfXJYScf68.pgp
Description: PGP signature



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