Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!pnx.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Length of C++ arrays allocated by operator new[] Date: Mon, 22 Aug 2011 12:27:25 +1200 Lines: 38 Message-ID: <9bdm3dFr0aU6@mid.individual.net> References: <4e4fb013$0$6568$9b4e6d93@newsspool3.arcor-online.net> <0YKdndDjrZg9f9LTnZ2dnUVZ8jSdnZ2d@giganews.com> <4e516d11$0$7610$9b4e6d93@newsspool1.arcor-online.net> <4e51803e$0$7615$9b4e6d93@newsspool1.arcor-online.net> <9bdj75Fr0aU2@mid.individual.net> <3dKdnR0UBufFAszTnZ2dnUVZ8qGdnZ2d@giganews.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net 3HwpwGqKNlzLjhz+zqw+vApfixHxJoLFfg5sswJP+Ke4FIQyLA Cancel-Lock: sha1:XnhDSHJHEAyKZc0/BZfbCaEBMP0= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: <3dKdnR0UBufFAszTnZ2dnUVZ8qGdnZ2d@giganews.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:9150 On 08/22/11 12:14 PM, Leigh Johnston wrote: > On 22/08/2011 00:38, Ian Collins wrote: >> On 08/22/11 11:04 AM, Leigh Johnston wrote: >>> On 21/08/2011 23:01, Marcel Müller wrote: >>>> On 21.08.11 23.32, Leigh Johnston wrote: >>>>> >>>>> Template code bloat is mostly over stated; non-template classes with >>>>> lots of inline functions can have similar "bloat". >>>> >>>> That's not what I mean. The most bloat comes from different >>>> instantiations of template classes that in fact produce binary the same >>>> code. E.g. std::vector will most likely result in identical code for all >>>> pointer types (except for member function pointers, of course). >>>> >>>> At least I have not seen a compiler that can share code between >>>> different template instantiations. >>> >>> That is the price you pay for not having to lose type information >>> however you can have a std::vector if you want. Template bloat >>> is less of a concern these days due to increased memory and storage >>> capacities even on smaller devices such as mobile phones. >> >> You don't even gave to loose type safety if you specialise vector for >> void* and derive privately from there. > > Indeed but pointers are not always the answer; the convenience and > possible performance characteristics of using a container as a container > of value type tend to outweigh concerns of code bloat these days IMHO > (assuming I am not writing code for a £20 toaster). The £20 toaster is an interesting example. At least one embedded tool chain I've used (Green Hills) when optimising for space will fold duplicate machine instructions into calls Thus all vectors of pointer type will generate the same machine code which gets merged. So the specialisation trick is unnecessary! -- Ian Collins