[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Growable arrays?
From: |
Mark H Weaver |
Subject: |
Re: Growable arrays? |
Date: |
Tue, 12 Jun 2012 17:03:20 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) |
David Kastrup <address@hidden> writes:
> Mark H Weaver <address@hidden> 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
- Re: Growable arrays?, (continued)
- Re: Growable arrays?, Noah Lavine, 2012/06/11
- Re: Growable arrays?, David Kastrup, 2012/06/11
- Re: Growable arrays?, Mark H Weaver, 2012/06/11
- Re: Growable arrays?, David Kastrup, 2012/06/12
- Re: Growable arrays?, Mark H Weaver, 2012/06/12
- Re: Growable arrays?, David Kastrup, 2012/06/12
- Re: Growable arrays?,
Mark H Weaver <=
- Re: Growable arrays?, David Kastrup, 2012/06/12
Re: Growable arrays?, Thien-Thi Nguyen, 2012/06/11
Re: Growable arrays?, Andy Wingo, 2012/06/11
- Re: Growable arrays?, David Kastrup, 2012/06/11
- Re: Growable arrays?, Andy Wingo, 2012/06/11
- Re: Growable arrays?, David Kastrup, 2012/06/11
- Re: Growable arrays?, David Kastrup, 2012/06/11
- Re: Growable arrays?, David Kastrup, 2012/06/11
- Re: Growable arrays?, Daniel Hartwig, 2012/06/11
- Re: Growable arrays?, David Kastrup, 2012/06/11