Thread: RE: [Dev-C++] STL Map question (Page 2)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Hossein H. <ult...@em...> - 2003-07-14 17:51:15
|
Ioannis,
> > Had you read "Effective STL," this has't been your answer.
>
>
> :-)
Sorry, but I can't view these cute faces because my mail server
provides text only.
> > Sometimes,
> > there are policies such as willing to have a constant-time operation
> > on the map that have higher proiority for the implementer (for any
> > reason they know). And achieving that runtime needs you to cut down
> > the use of size update after any operation of the map.
>
>
> Not any operation, size() has to be updated during insert() or erase() only.
>
> Also bool empty() const { return size()==0; } takes constant time.
Hmmm.... The only operation you have neglected is operator[]. But there
is another fine point. That is, when you are going to insert or erase
only one element, it is extremely easy to update size, but when dealing
with range counterparts, the story is not that easy.
> > I think the existance of nasty C++ implementations such as VC++6,
> > reveals that this is not just a fiction, and there even are wellknown
> > implementations who may have chosen that way.
>
>
> Anyway we are talking without any basis here, ...
Maybe! I don't have any problem if you don't want to continue it.
> ... the implementor can choose
> whatever method he likes to implement size() but if he calculated size()
> everytime it was called (or only the first time if no other change has been
> made) would be unwise since our code would wait for the internal loop of our
> thousands record counting to complete.
>
> In any case one would expect that the perofmrmance of size() in a if()
> statement wouldn't take 10 seconds. TC++PL provides the above check as a
> reasonable implementation I agree with it.
There may be some trade-off as I told. Anyway...
> > You'r right. But max-performance of what? I mean, if there is an
> > operation, say O, that has higher priority from your point of view (as
> > the implementer, or disigner, etc.), and you want O to be done in a
> > constant time, and that forces you to forget updating size after O,
> > will you still think that max-performance obliges you to have size as
> > an internal member?
>
>
> There is not any Big-Oh requirement of the standard both regarding size() or
> empty(). In theory empty() could be slower than size() (since there is not
> any kind of restriction), but I said let's try to be realists.
Theoritically, yes.
> I used VC++ 6 only to what it is best for. To learn C90. :-) Regarding ISO
> C++ it is crap. VC++ .NET 2002/2003 on the other hand are very good
> regarding C++ compliance.
I haven't still heard anything opposing that. But it takes time to see
what botchs it has, if any. (Generally, nothing in Software-houses such
as Microsoft is reliable.) So far, I agree with you.
> > I have just
> > realised that the compiler we were talking about was GCC, and I
> > hartapologise for the suspection I have had to his majesty. But
> > remember that I didn't know that's GCC. Knowing that, don't you still
> > preserve me the right of suspecting the implementation?
>
>
> Well I would start suspecting if the code was crawling.
Right!
> Does VC++ 6 crawl whem map::size() is used?
I'm not sure in this specific case, but I have encountered several
similar situations. Please don't ask me to enumerated them, because I
haven't documented them. But you can make search on interenet.
Wishes,
--Hossein
--
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup
CareerBuilder.com has over 400,000 jobs. Be smarter about your job search
http://corp.mail.com/careers
|
|
From: Ioannis V. <iv...@em...> - 2003-07-14 18:51:59
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Hossein Haeri
> Sent: Monday, July 14, 2003 8:51 PM
> To: dev...@li...
> Subject: RE: [Dev-C++] STL Map question
>
> > :-)
>
> Sorry, but I can't view these cute faces because my mail server
> provides text only.
Man you are very new to the Net. :-)
> > Also bool empty() const { return size()==0; } takes constant time.
>
> Hmmm.... The only operation you have neglected is operator[].
Yes you are right.
> But there
> is another fine point. That is, when you are going to insert or erase
> only one element, it is extremely easy to update size, but
> when dealing
> with range counterparts, the story is not that easy.
I do not think that it would be so difficult (e.g. --size; for every item
erased, where size the internal representation of size, and without any
checks if size>0).
In any case, map<>::empty() is a right solution to check whether the map is
empty, so in reality we have been quibbling the details here.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|
|
From: Ioannis V. <iv...@em...> - 2003-07-15 00:55:10
|
> -----Original Message----- > From: Ioannis Vranos [mailto:iv...@em...] > Sent: Tuesday, July 15, 2003 3:44 AM > To: Dev-C++ Mailing List (dev...@li...) > Subject: RE: [Dev-C++] STL Map question > > Regarding C99 I have read in Usenet (but was too bored to > check the standard) that char can have padding bits because > they believed that C90 allowed that, while C++ inherited from > C90 the fact that a char cannot have padding bits. And that's indeed true, I just checked C99. Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Hossein H. <ult...@em...> - 2003-07-15 10:57:15
|
Shane, > > When it breaks out into GDB in the crash, > > it leaves me at > > a "map::find" statement, which, when I step into it, I find > > that the key (an > > std::string) is valid, but the data portion, a pointer to an > > allocated User, > > is somehow fubar'd, because if I try to print (no different > > than getting the > > value of a variable in VC++ debugger) the pointer, GDB itself > > will indicate > > that the program crashed while attempting to execute > > something by GDB. This > > means that 1) the code crashes and drops me into the > > debugger, and 2) it is > > in fact crashing because of the variable value, as executing > > the single > > operation of printing the value causes an internal crash that > > GDB recovers > > from, but ends execution of the program. > > > This is happening because you use the library in an improper C style way. > Had the map contained objects instead of pointers you would find no record > when you used the find() and would get User(0) when accessed the key using > operator[]. Better use C++ as C++ and not as C. Yep! I agree. Maybe not a bad idea to follow this. > > The problem I am seeing, I have never seen in all my time > > programming, and I > > have a good 8 years background with C. Further issues with > > this, may result > > in me reverting UserList to a true linked list > > implementation, instead of > > STL, which could be the culprit even though I don't want to > > blame it. > > > !!! The problem is your programming approach, not the standard library! I do not want to offend you, but perhaps he is right. You have tested everything, right? Why don't you test this one? (Forgive me if you have done it before.) > > Even > > reverting temporarily to a C linked list may help me in > > travelling the list > > in the debugger to find out where the problem is (like if > > it's the last or > > first element, etc)... Short of testing my new changes, this > > will be the > > next step, to revert to a very slow and simple linked list > > until I can track > > down the problem. At least I have some direction, I > > appreciate the help > > everyone has offered. > > > The standard library provides a double linked list implementation, > std::list. But your problem is that you code in C with classes, not C++! Probabely yeah! Regards, --Hossein -- __________________________________________________________ Sign-up for your own FREE Personalized E-mail at Mail.com http://www.mail.com/?sr=signup CareerBuilder.com has over 400,000 jobs. Be smarter about your job search http://corp.mail.com/careers |
|
From: Ioannis V. <iv...@em...> - 2003-07-15 18:08:49
|
> -----Original Message-----
> From: Ioannis Vranos [mailto:iv...@em...]
> Sent: Tuesday, July 15, 2003 9:00 PM
> To: Dev-C++ Mailing List (dev...@li...)
> Subject: RE: [Dev-C++] STL Map question
>
> if(whatever1[p->first]+whatever2[p->first]+.... == 0)
What I wrote above is not good, it's behaviour is implementation dependent.
The right approach is to check each return value against 0, since they are
pointer values.
So thee above should be:
if(!whatever1[p->first] && !whatever2[p->first] && ... &&
!whatevern[p->first])
{
//....
}
Sorry but apparently the caffeine had not reached my mind yet.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|