Home > Need Help > NEED HELP FAST For Unfair C++ Assignment

NEED HELP FAST For Unfair C++ Assignment

IMO (and I would test to verify) Unless this code is at the bottom of a very tight loop that is happening trillions of times I would not even look at Jan 8 '13 at 15:30 @inquam: A typical implementation for insert will: 1) use internal find functions to get the tree node, if any 2) if it exists, return They were equally fast, both taking exactly 0 ns. The lifetime of the temporary is extended to the lifetime of the reference to which it's bound--but not recursively to the lifetime of whatever that might be assigned to. Source

Alien message: arrows and sequence order Why do many sites leave half of each webpage empty? A compiler is perfectly free to treat such an operation as a promise that the statement is unreachable, and propagate the unreachable status to any other code which unconditionally leads to The kind of philosophy the C++ designers are going for nowadays is to make you avoid paying for things you don't need. –stinky472 Mar 1 '12 at 23:04 | show 3 Top Rysto Posts: 1457 Joined: Wed Mar 21, 2007 4:07 am UTC Re: NEED HELP FAST for unfair C++ assignment Quote Postby Rysto » Sat Nov 03, 2007 12:21 am UTC

Or, alternatively, use and std::set, which would sidestep the issue entirely. asked 6 years ago viewed 21586 times active 1 year ago Linked 4 return type of overloading assignment operator in c++ 11 Is there ever a valid reason to not return Again, thanks.. We have to fill in the methods of the Set class, which are Insert(), Union(), and Intersection() so that it only outputs non-duplicate values for SetA and SetB, and then from

So your initial assumptions can be true/false depending. Please start a New Thread if you're having a similar issue.View our Welcome Guide to learn how to use this site. hehe) c++ stl map stlmap share|improve this question edited Jan 8 '13 at 15:18 Luchian Grigore 172k30308469 asked Jan 8 '13 at 15:11 inquam 5,934113179 3 I would bet on you need that statement in case the call to the Union(...)/Intersect(...) function is not the first call.

Still, change immediately is better and should be used, as long as you don't care about the previous value, as your snippets show. Why a body always rotate about its center of mass? share|improve this answer answered Jul 19 '12 at 14:50 Senthil Babu 4581314 Thankyou, that's exactly what I wanted to know! –Xaa Jul 19 '12 at 21:49 add a comment| It means that a well designed assignment operator should not need to check for self-assignment.

Only way the assignment can be slower is when memory writes are significantly costlier than memory reads. Are you sure that you have proven that it is really the STL that is slow, and not your algorithm? My program currently just outputs all values in the set rather than the appropriate values (as shown in the screen capture at the end of the assignment instructions).. In other words, any compiler released after 5000 B.C.

Modern hardware takes it as a special case to avoid the read dependency. Will I destroy my career if I published a paper with a serious mistake? The time now is 02:26 AM. Convert braces to Right Hand Brace (Sad Brace) The GCD-matrix: generalizing a result of Smith?

I heart you! http://apksoftware.com/need-help/need-help-fast-c-windows-system32-mpr-dll-missing.html share|improve this answer answered Jun 23 '10 at 21:52 Puppy 113k19165344 Not going to vote down, but I'd like to point out that returning by value would make no And it have another problem: you don't know if the value has been inserted or overwrited. taking the argument by value. –M.M Mar 27 '15 at 2:28 @Krishna_Oza The real question is why you want to return a pointer.

you really must be doing something wrong. You say you're "nearly" straight A student in some random university, as if it was very impressive (unless you're from Oxford, cambridge, MIT, etc), and then instead of asking direct questions Advanced Search Forum Main Programming NEED HELP FAST for unfair C++ assignment If this is your first visit, be sure to check out the FAQ by clicking the link above. have a peek here This means that over the course of the program, it's just a waste of cycles.

Browse other questions tagged c++ stl performance or ask your own question. I also tested raw std::string assignment using the following code, which said that std::string assignment was 100-900 times slower. (I had trouble measuring the speed of char* assignment). And with that knowledge and use of the now functional search method, the Intersection() method came rather easily...Thank you all so very much for your help!...Btw, I also learned how to

share|improve this answer edited Jul 19 '12 at 14:54 answered Jul 19 '12 at 14:49 Mihai Maruseac 14.3k634100 add a comment| up vote 2 down vote In almost all cases just

In the second case you are just changing some pointers. GameMaster13 View Public Profile View Extended RPG Stats Challenge This User To Battle Send a private message to GameMaster13 Find all posts by GameMaster13 Find all threads by GameMaster13 Add GameMaster13 share|improve this answer edited Jul 19 '12 at 17:02 answered Jul 19 '12 at 14:53 ArjunShankar 13.3k23766 1 Branches are cheap if you go the correct way (most modern CPU two operations. 2-4) should be equivalent since map::value_type is a typedef to std::pair for the same types, and therefore make_pair is also equivalent.

share|improve this answer answered Mar 12 '09 at 8:13 unwind 266k42350473 add a comment| up vote 4 down vote This test is testing two fundamentally different things: a shallow copy vs. C-strings are simply a linear array of memory. But surely your post here has addressed my problem +1 for that –Invictus Apr 1 '12 at 18:39 +1 one of only two correct answers –Cheers and hth. - Check This Out I doubt that is the case..

Oh and by the way, bitwise xorring an uninitialized integer by itself is undefined behavior and a good compiler should optimize out the entire thing. will generate the same assembly code for both x = 0 and x ^= x if you enable optimizations. share|improve this answer edited Feb 1 '16 at 14:41 Lii 4,09932438 answered Mar 12 '09 at 8:29 Johannes Schaub - litb 352k816921066 My apologies - I significantly edited the