constant variables are not always placed in shared memory



Hi,

I was investigating the memory footprint of the gnome libraries
when I realized that global constant variables initialized with
an object address are implicitly made writable in order to be
relocated. As a consequence, that are not placed into shared
memory.

For example, a constant array of string addresses is
not going to be shared as one could expect (the
strings are constant and are placed in shared memory):

static const char * const my_strings[] = {
 "hello", "world", "foo"
}

It seems to me that some of the standard gnome libraries
are declaring quite a lot of those pseudo-constant global
variable. For example, libxml2 is allocating about 44ko
of non-constant global data. Most of them are large constant
arrays of strings like in my example. Quite some memory could be saved by using numerical constants
instead of addresses when that is possible.

For example: replace my_string[i] by my_string(i) static const char str_char[] ="hello\0world\0foo\0" ;
   static const char * const str_offset[] = {
  0,   // offset of "hello"
  6,   // offset of "world"
  12   // offset of "foo"
}

#define my_strings(i) (&str_char[str_offset[i]])


Do you know if this is a know problem and if it is going
to be addressed? S. Chauveau
email: s chauveau chello nl



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