Topic: cost of namespaces?


Author: jcoffin@taeus.com (Jerry Coffin)
Date: 1999/04/29
Raw View
In article <7g7pqk$8ac@news.or.intel.com>,
abhijitgore_at_earthlink_dot_net@news.or.intel.com says...
>
> We have been using namespaces approx 4-5 levels deep.
>
> can anybody enlighten me on cost of using namespaces ? what are the
> recommended hierarchy levels (7) ? does having more namespaces affect
> compilation / linking speed? and how about runtime costs?

Starting with your last point: run-time cost will normally be
nonexistent.  In theory, if you did something like copying the name of
a type obtained from RTTI, it could be minutely slower due to a longer
name, but at worst you'd have to work pretty hard to measure this at
all.  Depending on the implementation, there's no guarantee that it
would even have an effect here.

During compilation and linking, there's likely to be a bit more
effect: for the compiler, there are more complex rules about how names
get looked up, which is likely to lead to a small slowdown in lookup
speeds.  OTOH, since there are likely to be fewer names visible at any
given scope, looking up an individual name might be a bit faster due
to individual hash tables not being as full.  (Depending on the
implementation, they might all be in one big hash table though...)

For the linker, about the only effect is that you typically end up
with symbols having longer names, and hashing a particular symbol will
normally be linear with respect to the length of the string.  Despite
this, the effect is usually negligible, simply because hashing the
names us usually a pretty small minority of the time anyway.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: scorp@btinternet.com (Dave Harris)
Date: 1999/04/29
Raw View
ron.natalie@sensor.com (Ron Natalie) wrote:
> Namespaces (and names for that matter) have no effect after
> linkage so you should not worry about that.

Although if you have a persistence system that stores class names in data
files, as is quite common, you will need to store some representation of
the namespace in the file as well.

Isn't there a chance that other, more standard reflective schemes will be
affected at runtime? For example, an implementation of typeid might decide
to use fully qualified class names.

  Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
      brangdon@cix.co.uk      |   And close your eyes with holy dread,
                              |  For he on honey dew hath fed
 http://www.bhresearch.co.uk/ |   And drunk the milk of Paradise."


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/04/29
Raw View
In article <7g7pqk$8ac@news.or.intel.com>, Abhijit Gore <abhijitgore_at_
earthlink_dot_net@news.or.intel.com> writes
>can anybody enlighten me on cost of using namespaces ? what are the
>recommended hierarchy levels (7) ? does having more namespaces affect
>compilation / linking speed? and how about runtime costs?

There are no runtime costs.  There may be some costs at compilation/link
time but I would be surprised if they were serious.


Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Abhijit Gore" <abhijitgore_at_earthlink_dot_net@news.or.intel.com>
Date: 1999/04/28
Raw View
We have been using namespaces approx 4-5 levels deep.

can anybody enlighten me on cost of using namespaces ? what are the
recommended hierarchy levels (7) ? does having more namespaces affect
compilation / linking speed? and how about runtime costs?

thanks

abhijit gore
abhijitgore_at_earthlink_dot_net




[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Ron Natalie <ron.natalie@sensor.com>
Date: 1999/04/28
Raw View
Abhijit Gore wrote:
>
> We have been using namespaces approx 4-5 levels deep.
>
> can anybody enlighten me on cost of using namespaces ? what are the
> recommended hierarchy levels (7) ? does having more namespaces affect
> compilation / linking speed? and how about runtime costs?
>

Namespaces (and names for that matter) have no effect after
linkage so you should not worry about that.

As for compile/link times, this is generally unimportant.
Actually, judicious use of namespaces probably could speed
things up by drastically reducing the number of symbols in
any given scope.



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1999/04/28
Raw View
"Abhijit Gore" <abhijitgore_at_earthlink_dot_net@news.or.intel.com> writes:

> can anybody enlighten me on cost of using namespaces ?

Some of the costs depend on the compiler. I see
- deeper nesting requires more typing, and may add more confusion to
  users of a library.
- deeper nesting may increase size of object files, and memory
  consumption of the compiler
- deeper nesting may reduce linking speed.

There are typically no runtime costs to namespaces.

Regards,
Martin


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]