Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 42023 invoked from network); 23 May 2007 19:25:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 May 2007 19:25:42 -0000 Received: (qmail 18539 invoked by uid 500); 23 May 2007 19:25:47 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 18528 invoked by uid 500); 23 May 2007 19:25:47 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 18517 invoked by uid 99); 23 May 2007 19:25:47 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 May 2007 12:25:47 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [208.30.140.160] (HELO moroha.quovadx.com) (208.30.140.160) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 May 2007 12:25:40 -0700 Received: from qxvcexch01.ad.quovadx.com ([192.168.170.59]) by moroha.quovadx.com (8.13.6/8.13.6) with ESMTP id l4NJOS9H017318 for ; Wed, 23 May 2007 19:24:28 GMT X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: std::vector intialization on HP-UX Date: Wed, 23 May 2007 13:24:16 -0600 Message-ID: In-Reply-To: <4654832B.20806@roguewave.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: std::vector intialization on HP-UX Thread-Index: AcedZVnxjtkGICpFRnenCWtEjXbSkQACozWw References: <4654832B.20806@roguewave.com> From: "Patrick Happel" To: X-Virus-Checked: Checked by ClamAV on apache.org Thanks for these answers, Martin! -Patrick=20 -----Original Message----- From: Martin Sebor [mailto:sebor@roguewave.com]=20 Sent: Wednesday, May 23, 2007 12:09 PM To: stdcxx-dev@incubator.apache.org Subject: Re: std::vector intialization on HP-UX Patrick Happel wrote: > Hello all, > I'm working with versions 4.1.2 and 4.1.0 of the STDCXX on HP-UX 11i > with aCC 3.63, and I've noticed that when a std::vector is constructed > with a size parameter, it's actually allocated as that size + 32=20 > additional elements. For example: > =20 > #include > #include > =20 > int main() { > std::vector testvec1(4); > std::cout << "Capacity: " << testvec1.capacity() << std::endl; =20 > std::cout << "Size: " << testvec1.size() << std::endl; return 0; } > =20 > When run will output: > =20 > [phappel@moe 15d]$ ./stdvectest > Capacity: 36 > Size: 4 > =20 > The HP-UX Standard Library will allocate 32 element sizes to a=20 > vector declared with a size less than 32, but will allocate as=20 > expected beyond that. STDCXX, however, seems like it will always add 32 to the size. > I'm curious if there is an explanation for this - is it perhaps some=20 > quirk of memory allocation or template instantiation on HP-UX? Any=20 > insight would be appreciated! Vector in stdcxx computes the capacity, C, from the desired size N, the Golden Ratio R (1.618), and the minimum capacity Cmin (32), using the following formula: C :=3D max (N * R, N + Cmin) This is based on the assumption that more vectors will grow than not, and that by how much they will grow is a function of their current size. The Golden Ratio is known to strike an optimum balance between the amount of utilized space and the amount unused space. See, for example: http://en.wikipedia.org/wiki/Golden_ratio The HP implementation of vector (Rogue Wave libstd 2.2.1) seems to use a simpler formula: C :=3D max (32, N) The classic implementation of vector shipped by HP (Rogue Wave libstd 1.2.1) as well as other popular implementations such as GNU libstdc++ or IBM XLC++ simply use N: C :=3D N Martin