g_malloc overhead



hi:

I working with visual c++ in Windows and i find glib very useful for many C task, but i am worry about the g_malloc overhead.

We really need a new malloc??

gpointer
g_malloc (gsize n_bytes)
{
 if (G_UNLIKELY (!g_mem_initialized))
   g_mem_init_nomessage();
 if (G_LIKELY (n_bytes))
   {
     gpointer mem;

     mem = glib_mem_vtable.malloc (n_bytes);
     if (mem)
   return mem;

     g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes",
              G_STRLOC, n_bytes);
   }

 return NULL;
}





What are the advantages of use a glib_mem_vtable ???. I think we have the same malloc function in all operating systems?.
static GMemVTable glib_mem_vtable = {
 standard_malloc,
 standard_realloc,
 standard_free,
 standard_calloc,
 standard_try_malloc,
 standard_try_realloc,
};


Other overhead i see is the open dir/file funtions, where in windows we need do the utf8 to utf16 everytime in windows. If JAVA,.NET and Qt use utf16 by default why in gnome world we use utf8 by default?.

.....
#ifdef G_OS_WIN32
 wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, error);

 if (wpath == NULL)
   return NULL;

 dir = g_new (GDir, 1);

 dir->wdirp = _wopendir (wpath);
 g_free (wpath);

 if (dir->wdirp)
   return dir;

.........
Regards.





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