help-gplusplus
[Top][All Lists]
Advanced

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

Re: Anonymous namespace implications - footprints


From: Paul Pluzhnikov
Subject: Re: Anonymous namespace implications - footprints
Date: Sun, 18 Jun 2006 14:33:53 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

kobi.cohenarazi@gmail.com writes:

> I've posted it in moderated c++ as well, but it seems that it would be
> an interest here as well, since someone says it is kind of optimizer
> artifact.

AFAICT this has noting to do with optimizer, and it's not really
of any interest to anyone, except a few people building for extremely
memory-constrained embedded systems (who generally stay away from C++
anyway).

> The problem - unnamed/anonymous namespace makes the text segment
> bigger. 

How much bigger?

> w/ namespace
> % size ./a.out
>    text    data     bss     dec     hex filename
>    1774     308      72    2154     86a ./a.out
>
> w/ static
>  size ./a.out
>    text    data     bss     dec     hex filename
>    1690     308      72    2070     816 ./a.out


So there is a 5% size difference, big deal.

If you *look* where that difference came from (with "nm" or "readelf -S"), 
you'll discover that anonymous namespace isn't actually anonymous;
its name is just a randomly-generated string of 40+ characters [1],
and you pay that price for each exposed symbol.

If this anounts to any significant overhead in your program, you
probably have too many "global functions", which are too short;
or too many global data.

Cheers,

[1] The name also includes pathname of the compilation unit, so
overhead increses significantly if one does "g++ -c `pwd`/junk.cc"
compared to "g++ -c junk.cc"
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]