container<POD> refactoring

Bo Persson bop@gmb.dk
Mon Sep 20 20:28:00 GMT 2004


----- Original Message ----- 
From: "Gabriel Dos Reis" <gdr@cs.tamu.edu>
To: "Joe Buck" <Joe.Buck@synopsys.COM>
Cc: <libstdc++@gcc.gnu.org>
Sent: Monday, September 20, 2004 8:28 PM
Subject: Re: container<POD> refactoring


> Joe Buck <Joe.Buck@synopsys.COM> writes:
>
> | Has anyone done any thinking about adding specializations for 
> avoiding
> | bloat with containers of POD types?  For std::vector, it seems that 
> all
> | of the out-of-line functions other than the == and < operators 
> depend
> | only on the size of the POD, and nothing else.
>
> I would say this is something best done at the linker level.
> User-codes may detect -- at program source level -- whether we
> specialize or not.
>
> I've heard persistent reports that Microsoft's linker is capable (and 
> is
> actually doing it) of sharing morally same specializations codes.

It really does!

It's kind of a by-product of their instantiation model. The compiler 
adds instantiations of templates in any object file that needs one, 
using some kind of "common block" for the code.

The linker then compares each "common block" and discards any excess 
copies. The primary use was of course to discard multiple copies of the 
same function, but it also happens to work on anything that just happen 
to generate the same code, like containers of same-sized PODs.


Bo Persson





More information about the Libstdc++ mailing list