I did test it, and it was just as fast either way (g++
3.3/MSVC++ 7.0 on Windows 2000 a year or so ago).
Regards,
MIke
On Thursday 09 Jun 2005 23:16, fons adriaensen wrote:
>
> int access(int *v, int i)
> {
> return v[i];
> }
Of course, passing that pointer by value is horribly inefficient.
int access(int *const &v, int i)
{
return v[i];
}
Chris
On Thu, Jun 09, 2005 at 09:39:21PM +0300, Jussi Laako wrote:
> > int access(std::vector v, int i)
> > {
> > return v[i];
> > }
>
> At least you are making copy here, should be
>
> int access(std::vector &v, int i)
No such problem with
int access(int *v, int i)
{
return v[i];
}
:-) :-)
On Thu, Jun 09, 2005 at 08:23:57PM +0100, Chris Cannam wrote:
> On Thursday 09 Jun 2005 20:07, stefan kersten wrote:
> > On Thu, Jun 09, 2005 at 09:39:21PM +0300, Jussi Laako wrote:
> > > On Thu, 2005-06-09 at 18:14 +0200, stefan kersten wrote:
> > > > int access(std::vector v, int i)
> > >
> > > A
>a: a.cpp:5: A::A(const A&): Assertion `0' failed.
as an uncle of mine liked to quote "subtle as a flying mallet" :))
On Thursday 09 Jun 2005 20:07, stefan kersten wrote:
> On Thu, Jun 09, 2005 at 09:39:21PM +0300, Jussi Laako wrote:
> > On Thu, 2005-06-09 at 18:14 +0200, stefan kersten wrote:
> > > int access(std::vector v, int i)
> >
> > At least you are making copy here, should be
> > int access(std::vector &v,
On Thu, Jun 09, 2005 at 09:39:21PM +0300, Jussi Laako wrote:
> On Thu, 2005-06-09 at 18:14 +0200, stefan kersten wrote:
>
> > int access(std::vector v, int i)
> > {
> > return v[i];
> > }
>
> At least you are making copy here, should be
>
> int access(std::vector &v, int i)
actually not, s
>#include
>
>int access(int* v, int i)
>{=20
>return v[i];
>}=20
>
>int access(std::vector v, int i)
ahem. pass by reference vs. pass by value?
On Thu, 2005-06-09 at 18:14 +0200, stefan kersten wrote:
> int access(std::vector v, int i)
> {
> return v[i];
> }
At least you are making copy here, should be
int access(std::vector &v, int i)
--
Jussi Laako <[EMAIL PROTECTED]>
On Thu, Jun 09, 2005 at 11:41:00PM +0900, David Cournapeau wrote:
> The other problem "is [] as efficient for vector and plain
> c array ?"
possibly maybe:
#include
int access(int* v, int i)
{
return v[i];
}
int access(std::vector v, int i)
{
return v[i];
}
produces (g++ -fv
On Thu, 9 Jun 2005 23:41 , David Cournapeau <[EMAIL PROTECTED]> sent:
>On 6/9/05, stefan kersten [EMAIL PROTECTED]> wrote:
>> On Thu, Jun 09, 2005 at 10:31:35PM +0900, David Cournapeau wrote:
>> > _Z6vectorSt6vectorIiSaIiEE:
>> > .LFB539:
>> > .L2:
>> > .L7:
>> > pushl %ebp
>> > .LCFI0:
On 6/9/05, stefan kersten <[EMAIL PROTECTED]> wrote:
> On Thu, Jun 09, 2005 at 10:31:35PM +0900, David Cournapeau wrote:
> > _Z6vectorSt6vectorIiSaIiEE:
> > .LFB539:
> > .L2:
> > .L7:
> > pushl %ebp
> > .LCFI0:
> > movl%esp, %ebp
> > .LCFI1:
> > popl%ebp
> > ret
>
On Thu, Jun 09, 2005 at 10:31:35PM +0900, David Cournapeau wrote:
> _Z6vectorSt6vectorIiSaIiEE:
> .LFB539:
> .L2:
> .L7:
> pushl %ebp
> .LCFI0:
> movl%esp, %ebp
> .LCFI1:
> popl%ebp
> ret
you've been bitten by the optimizer, this function does
nothing but return (
> No, I am not. I cannot find the information on the C++ faq right now,
> but If m pretty sure that it is written in the book of Stroustrup.
>
Of course, once I press the send button, I find the relevant webpage:
http://www.research.att.com/~bs/3rd_tour2.pdf (page 9 of the pdf)
"3.7.2 Range Che
On 6/9/05, Erik de Castro Lopo <[EMAIL PROTECTED]> wrote:
> David Cournapeau wrote:
>
> > [EMAIL PROTECTED] wrote:
> >
> > >
> > >I was under the impression that there was bounds checking going on with
> > >vectors. Is this not the case?
> > >
> > >
> > >
> > Not necesserally: if you are usin
David Cournapeau wrote:
> [EMAIL PROTECTED] wrote:
>
> >
> >I was under the impression that there was bounds checking going on with
> >vectors. Is this not the case?
> >
> >
> >
> Not necesserally: if you are using operator (), yes, if you use operator
> [], no.
I think you are all guess
On Thursday 09 June 2005 12:46, Chris Cannam wrote:
> Jan Depner:
> > I was under the impression that there was bounds checking going on with
> > vectors. Is this not the case?
> Nope.
As far as I know the [] is not checked. but at() is...
Arnold
--
There is a theory which states that if ever
David Cournapeau wrote:
[EMAIL PROTECTED] wrote:
I was under the impression that there was bounds checking going on
with
vectors. Is this not the case?
Not necesserally: if you are using operator (), yes, if you use
operator [], no.
David
Sorry, you should read "vec.at(index) d
[EMAIL PROTECTED] wrote:
I was under the impression that there was bounds checking going on with
vectors. Is this not the case?
Not necesserally: if you are using operator (), yes, if you use operator
[], no.
David
Jan Depner:
> I was under the impression that there was bounds checking going on with
> vectors. Is this not the case?
Nope.
Chris
On Thu, 9 Jun 2005 10:05 , 'Chris Cannam' <[EMAIL PROTECTED]> sent:
>N Smethurst:
>> Since a vector is a wrapped C array (i.e. contigous), the [] operator
>> compiles to the C equivalent when optimisation is turned on.
>
>I was thinking of iterator operations, having vaguely recalled that the v
N Smethurst:
> Since a vector is a wrapped C array (i.e. contigous), the [] operator
> compiles to the C equivalent when optimisation is turned on.
I was thinking of iterator operations, having vaguely recalled that the vector
iterator in the gcc library had at some point changed from an actual
22 matches
Mail list logo