From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: Growable arrays? Date: Tue, 12 Jun 2012 17:03:20 -0400 Message-ID: <878vfs1bvr.fsf@netris.org> References: <87hauku0mb.fsf@fencepost.gnu.org> <873962sbu0.fsf@fencepost.gnu.org> <87y5nuqpii.fsf@fencepost.gnu.org> <871ulmqbhj.fsf@fencepost.gnu.org> <87pq951k80.fsf@netris.org> <87mx48ooua.fsf@fencepost.gnu.org> <87haug1d89.fsf@netris.org> <871ulkntoj.fsf@fencepost.gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1339535137 27010 80.91.229.3 (12 Jun 2012 21:05:37 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 12 Jun 2012 21:05:37 +0000 (UTC) Cc: guile-devel@gnu.org To: David Kastrup Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Jun 12 23:05:35 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SeYHJ-0004ZQ-24 for guile-devel@m.gmane.org; Tue, 12 Jun 2012 23:05:29 +0200 Original-Received: from localhost ([::1]:57896 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SeYHI-0002WF-PV for guile-devel@m.gmane.org; Tue, 12 Jun 2012 17:05:28 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:55590) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SeYHF-0002Vz-Vp for guile-devel@gnu.org; Tue, 12 Jun 2012 17:05:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SeYHD-0007SZ-Nf for guile-devel@gnu.org; Tue, 12 Jun 2012 17:05:25 -0400 Original-Received: from world.peace.net ([96.39.62.75]:60387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SeYHD-0007SK-It; Tue, 12 Jun 2012 17:05:23 -0400 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=yeeloong) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1SeYH5-0003fk-Kf; Tue, 12 Jun 2012 17:05:15 -0400 In-Reply-To: <871ulkntoj.fsf@fencepost.gnu.org> (David Kastrup's message of "Tue, 12 Jun 2012 22:47:56 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:14611 Archived-At: David Kastrup writes: > Mark H Weaver writes: >> C++, like Scheme, already supports fixed-size vectors in the core >> language, so it would be redundant to include them in a library. > > A vector with run-time determined size? Which variant of C++ offers > that? Um, this is basic functionality that has been available in C since the beginning, e.g.: int *v = malloc (len * sizeof(int)). Admittedly, I've not written a single line of C++ in the last 15 years, but as I recall C++ has the new[] operator that handles this nicely for arbitrary classes. >> If C++ supported _only_ resizable vectors, such that there was no way >> to avoid the additional level of pointer indirection, and all derived >> data structures had to be built upon these doubly-indirected vectors, >> then I'd expect that the efficiency impact would be quite significant >> in both time and space. > > Reality check: C++ does not offer structs/classes containing vectors of > run-time determinable size. You need to allocate a pointer for them. Yes, of course you need to allocate a block, and you need to do that for Scheme vectors as well. However, a resizable vector object needs _two_ blocks: one block containing the elements, and another block containing the length and the pointer to the elements. That means _two_ pointer lookups to access an element, as opposed to one for fixed-size vectors. Mark