I'm in detoxification right now. Should be able to get hooked again in a few months... :doh:
Progamming looks like taking drugs... I think I did an overdose. ;-P
I'm in detoxification right now. Should be able to get hooked again in a few months... :doh:
Progamming looks like taking drugs... I think I did an overdose. ;-P
I have Coffee Compiler 3.2 and Double Expresso Linker 4.3 to help me every morning. :-D Sometimes, when Headache 1.4 (the infinite loop manager) seems to be apparent in action, I use the debugger Aspirin 3.3 to help me. :doh: Have a nice day! :-D Stephan
Progamming looks like taking drugs... I think I did an overdose. ;-P
Since it took you a while, you can imagine how funny it was to me to find it. I just wanted you to go trough what I had to. And since us programmer are supposed to be more "logical" :-D than everyone else, I thought I was not mandatory to point where the bug was. :) For the time needed to count the lines of code, I didn't have to take this time, because they had already counted it and was proud of the count. :confused: They were trying to beat 4 millions lines of code. It was a goal for them! Guess why I quit the company a couple of weeks after!! :(( I agree with you that fixing the error may cause a bug. It's one of the answer they gave me too. Cheers, Stephan
Progamming looks like taking drugs... I think I did an overdose. ;-P
Yeah, definitively!
Progamming looks like taking drugs... I think I did an overdose. ;-P
And believe what? For them, it wasn't a bug, since it always worked "well" before! At first, they tought it was a typing mistake made accidentaly by me until they looked into SourceSafe and agreed that the mistake was there too, since a couple of years before! Progamming looks like taking drugs... I think I did an overdose. ;-P
A couple of year ago, I worked for a compagny who were making vision sensing application for wood machinery. Their code (in C++) was a lot complicated, with lots of subclassing, and for the worst part of it, almost every options parameters controlling the code sequence were implemented with #if #then to "save some processor time". (The main core of the program was developped in Turbo-Dos like 15 years ago, then ported to Visual 6.0. It's why they used those #if #then...) The code was more than 3 millions line of code!!! That's it for the introduction. (You may already laugh!!) But one day, I came across a fonction used to connect a RS232 port. This is the interesting part inside the fonction : ...some code here if( strcmp( lpszPortName, "COM1") == 0 ); { // Connect the COM1 port ...some code here } else if( strcmp( lpszPortName, "COM2") == 0 ) { // Connect the COM2 port ...some code here } else ... So I asked one of the guy who were working there since a very long time, why they didn't corrected that error... He told me "It always worked well before, and the compiler never notified any error so leave it like that..." Do you know why I found this little error in 3 millions of code lines? Because this sequence was part of a library used in the main program, and because that library had never been recompiled since its first release 10 years before! For some reasons, I just forgot to follow a little "office rule" that was to never recompile all projects in a workspace in a single shot. I did it "oh unfortunately" then the compiler hit that error immediately!! Progamming looks like taking drugs... I think I did an overdose. ;-P -- modified at 3:09 Tuesday 13th March, 2007
Thanks!!! Never thought about that one!! It make sense and prevent us to do stupid logical error in a if statement. Now, I just have to remember to code like this.
Progamming looks like taking drugs... I think I did an overdose. ;-P
Oh oups!! By the way, thanks! Progamming looks like taking drugs... I think I did an overdose. ;-P
Hey guys, I just got a weird idea. It's not about programming. It's about a little "greeny" friend we have here. I've been surfing on CodeProject since its early starts. I've always saw that little green mascot near every CodeProject titles. Does someone knows if it have a name? If not, should we do a little contest to give it one? I think we have to do this if it's not already done. Think about it!:-D Cheers, Stef Progamming looks like taking drugs... I think I did an overdose. ;-P
Forget my last post Zdeslav! I found what's going wrong, I missed to place the "inline" instruction in my function header!!:(( Sorry. Ok, now I go sleep, I think I need it! Ha ha ha! Thanks for help! Progamming looks like taking drugs... I think I did an overdose. ;-P
Oups!! :-D I've tested every code in debug to be sure that everything was swapped properly but forgot this one:^)! Thanks Zdeslav! For sure, I will look for the book you're talking about. I ran my test program with swap codes exactly identical to the ones you tested yourself and it gives me always the same result, the assembly code is always still faster. I don't understand. Maybe it depend on the way it is compiled and on which CPU it is ran... I use MS Visual C++ 6.0 Compiler version : MS 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86 Linker version : MS Incremental Linker Version 6.00.8168 My CPU is : Intel Pentium III, 450MHz SDK installed : MS SDK for WinXP SP2 My project settings are the base one for an MFC dialog-based application. Also, every loops are called within a worker thread sets with normal priority. Progamming looks like taking drugs... I think I did an overdose. ;-P
Hey, I found something interesting while playing with my test application, I did a modification to UltraSwap2 and made this one :
_inline PVOID UltraSwap3( LONG* a, LONG* b )
{
__asm mov eax, dword ptr [a]
*a = *b;
__asm mov dword ptr [b], eax
}
It's not quite elegant for a "supposed" assembly but look at the result in Release mode : UltraSwap2 after 1 loops : 0.004190476 ms UltraSwap2 after 1000 loops : 0.016761902 ms UltraSwap2 after 10000 loops : 0.138285693 ms UltraSwap2 after 1000000 loops : 13.729674098 ms UltraSwap2 after 10000000 loops : 218.611242878 ms ------------------------------------- UltraSwap3 after 1 loops : 0.003352380 ms UltraSwap3 after 1000 loops : 0.013409522 ms UltraSwap3 after 10000 loops : 0.092190462 ms UltraSwap3 after 1000000 loops : 8.895541502 ms UltraSwap3 after 10000000 loops : 128.132170951 ms It's a lot more faster for long loops!! Stef Progamming looks like taking drugs... I think I did an overdose. ;-P
That's what I thought at first sight. I didn't tested Zdeslav's code, I just relied on the comment he gaves us, it seemed to have sence. I didn't thought to scan the code in assembly:^), my fault:) ! So I did a little test with performance counters, just to see what's the real result... :-D I tested the code on my old P3 450, I've tested each solution 10 times and did an average. For the Zdeslav solution:
void UltraSwap( LONG* a, LONG* b ) { LONG t = *b; *b = *a; *a = t; }
IN DEBUG IN RELEASE
One single call : 0.004190476 ms 0.004190476 ms
1000 calls loop : 0.186895210 ms 0.035199995 ms
10000 calls loop : 1.822018770 ms 0.307580906 ms
and for the suhredayan solution:
_inline PVOID UltraSwap2( LONG* a, LONG* b ) { __asm mov eax, dword ptr [a] __asm mov ebx, dword ptr [b] __asm mov dword ptr [a], ebx __asm mov dword ptr [b], eax }
IN DEBUG IN RELEASE
One single call : 0.004190476 ms 0.003352380 ms
1000 calls loop : 0.170133307 ms 0.016761902 ms
10000 calls loop : 1.599923566 ms 0.158399976 ms
So, know, everyone can see the results. I don't think I have to explain furter... :-D In debug mode, there is not a lot of difference but after a 10000 calls loop in release mode, now I'm sure that UltraSwap2 is the great winner! It just took the half time of the other one. If you want to see my test code, let me know, I will try to post it. Thanks suhredayan for your advise, you pointed me on the right track!! Have a nice day, Stef Progamming looks like taking drugs... I think I did an overdose. ;-P
Thanks everyone! I think I will use the UltraSwap2 solution from Zdeslav, since it is more faster than all the other ones. It was my mistake to think that it should be faster to do it in assembly code. But if I refer at my wishes to learn some assembly code, the suhredayan solution is what I was looking for. I used to code on some industrial programmable controllers a long time ago and it was in assembly code. But both syntax and function names wasn't the same. Great help guys! Stef Progamming looks like taking drugs... I think I did an overdose. ;-P
Hi everyone, I need to know if there is a better way to swap variables values in assembly code. I have a thread that sort some variables and I wanted to make it as fast as possible. Also, I wanted to do it in assembly code just to learn a little about it. It is my first attempt in assembly code so apologize for mistakes. If you know how to do it in a better way, let me know! The code you see below works great but I'm sure we can do that in a more "fancy" way. This how I call the function : UltraSwap( &Var1, &Var2 );
Then this is the function in assembly code : #pragma warning (disable:4035) // disable warning 4035 (function must return something) _inline PVOID UltraSwap( LONG* a, LONG* b ) { LONG x = *a; LONG y = *b; __asm mov eax, x __asm mov ebx, y __asm mov x, ebx __asm mov y, eax *a = x; *b = y; } #pragma warning (default:4035) // Reenable it
The only thing I don't understand is that I can't move *x
or *y
into eax and ebx respectively. I had to declare two local variables to achieve that. I think that just declaring that will take some times. I didn't tested what's the difference in time between swapping two variables in C++ code and in assembly because I didn't know how to, since GetTickCount()
isn't too much reliable and not so much fast. Let me know if you guys find something! Have a nice day! Stef Progamming looks like taking drugs... I think I did an overdose. ;-P
I get it!! :eek: I just forgot size the array of CButton pointers... myButton = new CButton*; myButton[nIndex] = new CButton;
Now, I just have to find out how to resize it ! Tanks a lot Stef Progamming looks like taking drugs... I think I did an overdose. ;-P
It doesn't work... It stop at: myButton[nIndex]=new CButton;
I have declared myButton like this : CButton** myButton;
Any Idea. I have an headhache so, my brain doesn't work as much as I want !:cool: Progamming looks like taking drugs... I think I did an overdose. ;-P
Hi everyone! I need to create a button array that can be resized. I tought it was easy like in VB but I got a problem. I'm unable to create buttons! For example, I placed this is my header file : //Pointer to button array CButton* myButton; //Hold number of buttons in the list int nbButtons; //Add a button in the list void InsertButton(LPCTSTR lpszText);
Then in the implementation file, I've set void CLinkList::InsertButton(LPCTSTR lpszText) { // Memory allocation ( preserve existing!! ) if(nbButtons<1) // First memory allocation myButton=(CButton*)malloc(sizeof(CButton)*(nbButtons+1)); else // Dynamic realoccation myButton=(CButton*)realloc(myButton, sizeof(CButton)* (nbButtons+1)); // Set location CRect rect(0,nbButtons*25,60,20); // Create the button control myButton[nIndex].Create( lpszText, WS_VISIBLE | WS_CHILD, rect, this, GetDlgCtrlID() ); // Increment number of buttons in the list nbButtons++; }
But I'm not able to create any button. I didn't get any assertion error but it stop within the CButton::Create function. I don't have any idea of what is the problem. I know that if I create a static array like : CButton myButton[30];
it works very well... What's wrong with the way I do, and how can I solve it? Notice that I want my array to be resized because I don't want to hold a "big" static array. And probably because I'm curious to know how it works too! :-D It will be very appreciated if somebody here could help me!! Stef Progamming looks like taking drugs... I think I did an overdose. ;-P
Hi everyone, I need help and suggestion with something I will program soon. Look this post for explanation. http://www.codeproject.com/script/comments/forums.asp?forumid=1647&mode=all&userid=128795&select=406290&df=100#xx406290xx Thanx ! Progamming looks like taking drugs... I think I did an overdose. ;-P
No ones have an idea ??? Progamming looks like taking drugs... I think I did an overdose. ;-P