Re: mcedit issues
- From: Roland Illig <roland illig gmx de>
- To: "Andrew V. Samoilov" <andrew email zp ua>
- Cc: mc-devel gnome org
- Subject: Re: mcedit issues
- Date: Fri, 05 Nov 2004 15:57:50 +0100
Andrew V. Samoilov wrote:
Also as far as I remember glib 1.2 allocates initially 1K memory area on default
and doubles this area each time to fit string. I am using LiveCD and
embeded distros on low memory machines with specially stripped mc,
so I dont glad to see this memory allocation strategy.
Yes, you're correct. I just checked glib-1.2, too.
We can argue about which strategy of allocation (glib, strcats() or
n*strlen + m) is better/worse, but I don't think it makes much
difference. Additionally, the string is freed in the same function call,
so it is really temporary.
I wrote a little test program for the glib-1.2 memory usage. You should
not use glib-1.2 at all if your memory is limited.
break = 0x8049924 (init)
break = 0x806b000 (after g_malloc)
break = 0x806a000 (after g_free)
break = 0x806a000 (after g_string_new)
break = 0x806a000 (after g_string_free)
Here you see that glib allocates quite much memory, and that it does not
matter if we use GString or not.
Roland
#include <unistd.h>
#include <stdio.h>
#include <glib.h>
static void ps(const char *s)
{
fprintf(stderr, "break = %p (%s)\n", sbrk(0), s);
}
int main(void)
{
GString *s;
void *p;
ps("init");
p = g_malloc(100);
ps("after g_malloc");
g_free(p);
ps("after g_free");
s = g_string_new("foo");
ps("after g_string_new");
g_string_free (s, TRUE);
ps("after g_string_free");
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]