Hi,

I'm still working on my Book Class using vector.
due to a strange behavior of vector function : push_back(), i decided to
do a simple test.
the result is absolutely the same...it's to say :

I wrote this :
//-------------
vector<int> Pokus;

Pokus.push_back(10);
Pokus.push_back(20);

when i control in my Local window the values, i have :

Pokus
_MyFirst 10
_MyLast *? a random value but not 20
_Myend *? the same random value than _MyLast

so i was thinking that push_back function reallocate memory in case of
need...but it seems to not work.

Does anyone already had this behavior or just me ?

thx,
Maileen

Re: strange behavior of Vector by Doug

Doug
Sat Jun 19 12:38:37 CDT 2004

Maileen wrote:

>Hi,
>
>I'm still working on my Book Class using vector.
>due to a strange behavior of vector function : push_back(), i decided to
>do a simple test.
>the result is absolutely the same...it's to say :
>
>I wrote this :
>//-------------
>vector<int> Pokus;
>
>Pokus.push_back(10);
>Pokus.push_back(20);
>
>when i control in my Local window the values, i have :
>
>Pokus
> _MyFirst 10
> _MyLast *? a random value but not 20
> _Myend *? the same random value than _MyLast
>
>so i was thinking that push_back function reallocate memory in case of
>need...but it seems to not work.

It works. Unfortunately, the debugger is not too adept at helping you view
objects stored in containers.

>Does anyone already had this behavior or just me ?

Looking at the source code, _Myfirst points to the start of the vector's
storage, and confusingly, _Mylast equals end(), and _Myend points to
_Myfirst+capacity(). As you know, end() points one past the last element
stored in the vector, or for an empty vector, equals begin(), so it never,
ever points to an actual vector element.

--
Doug Harrison
Microsoft MVP - Visual C++

Re: strange behavior of Vector by Maileen

Maileen
Sat Jun 19 12:55:38 CDT 2004

thanks Doug,

I just realized it at the same time than i read you threat.
It's true that it's confusing...that's why i was :(

MS could improve this a little bit :)
because i think that i will not be the only one to be trapped with it.

Maileen

Doug Harrison [MVP] wrote:

> Maileen wrote:
>
>
>>Hi,
>>
>>I'm still working on my Book Class using vector.
>>due to a strange behavior of vector function : push_back(), i decided to
>>do a simple test.
>>the result is absolutely the same...it's to say :
>>
>>I wrote this :
>>//-------------
>>vector<int> Pokus;
>>
>>Pokus.push_back(10);
>>Pokus.push_back(20);
>>
>>when i control in my Local window the values, i have :
>>
>>Pokus
>> _MyFirst 10
>> _MyLast *? a random value but not 20
>> _Myend *? the same random value than _MyLast
>>
>>so i was thinking that push_back function reallocate memory in case of
>>need...but it seems to not work.
>
>
> It works. Unfortunately, the debugger is not too adept at helping you view
> objects stored in containers.
>
>
>>Does anyone already had this behavior or just me ?
>
>
> Looking at the source code, _Myfirst points to the start of the vector's
> storage, and confusingly, _Mylast equals end(), and _Myend points to
> _Myfirst+capacity(). As you know, end() points one past the last element
> stored in the vector, or for an empty vector, equals begin(), so it never,
> ever points to an actual vector element.
>


Re: strange behavior of Vector by Kyle

Kyle
Sat Jun 19 16:40:13 CDT 2004

> MS could improve this a little bit :)

They can't actually. As far as i know its standarized behaviour or vector so
MS has nothing to do with that ...


>
> Maileen
>
> Doug Harrison [MVP] wrote:
>
> > Maileen wrote:
> >
> >
> >>Hi,
> >>
> >>I'm still working on my Book Class using vector.
> >>due to a strange behavior of vector function : push_back(), i decided to
> >>do a simple test.
> >>the result is absolutely the same...it's to say :
> >>
> >>I wrote this :
> >>//-------------
> >>vector<int> Pokus;
> >>
> >>Pokus.push_back(10);
> >>Pokus.push_back(20);
> >>
> >>when i control in my Local window the values, i have :
> >>
> >>Pokus
> >> _MyFirst 10
> >> _MyLast *? a random value but not 20
> >> _Myend *? the same random value than _MyLast
> >>
> >>so i was thinking that push_back function reallocate memory in case of
> >>need...but it seems to not work.
> >
> >
> > It works. Unfortunately, the debugger is not too adept at helping you
view
> > objects stored in containers.
> >
> >
> >>Does anyone already had this behavior or just me ?
> >
> >
> > Looking at the source code, _Myfirst points to the start of the vector's
> > storage, and confusingly, _Mylast equals end(), and _Myend points to
> > _Myfirst+capacity(). As you know, end() points one past the last element
> > stored in the vector, or for an empty vector, equals begin(), so it
never,
> > ever points to an actual vector element.
> >
>



Re: strange behavior of Vector by P

P
Sat Jun 19 16:51:53 CDT 2004

"Maileen" <nospan@email.com> wrote in message
news:%23wrfiaiVEHA.644@tk2msftngp13.phx.gbl...

> thanks Doug,
>
> I just realized it at the same time than i read you threat.
> It's true that it's confusing...that's why i was :(
>
> MS could improve this a little bit :)
> because i think that i will not be the only one to be trapped with it.

So you're confused by the fact that an STL container maintains
a pointer to just past the last actual element, when the
whole frigging STL works that way? What do you think should
be improved? (And while you're at it, make sure you explain
how to represent an empty vector.)

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com



Re: strange behavior of Vector by James

James
Fri Jun 25 09:49:28 CDT 2004

P.J., Kyle,

What Maileen wants improved is the values displayed by the debugger,
which do not necessarily have to be the same as the implementation-defined
internal values.

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)

> So you're confused by the fact that an STL container maintains
> a pointer to just past the last actual element, when the
> whole frigging STL works that way? What do you think should
> be improved? (And while you're at it, make sure you explain
> how to represent an empty vector.)



Re: strange behavior of Vector by Tim

Tim
Sat Jun 26 06:00:00 CDT 2004

James Curran wrote:
> P.J., Kyle,
>
> What Maileen wants improved is the values displayed by the
> debugger, which do not necessarily have to be the same as the
> implementation-defined internal values.

Then Maileen should look at Visual Studio 2005 when it comes out.

--
Tim Robinson (MVP, Windows SDK)
http://mobius.sourceforge.net/