|
strlen() is slowing your code. Try calculating the string length outside the loop.
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
it is a test, that is why inside loop.
i can put strlen out of loop, but can't put it out of my program.
includeh10
|
|
|
|
|
includeh10 wrote:
i can put strlen out of loop, but can't put it out of my program.
That's what Nick said. It's being called over and over when you only need to call it once. It is the bottleneck in this code because you call it over and over needlessly.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Although I agree with Nick and Christian that the strlen should be out of the loop I also think it's really besides the point.
You're wondering how 0 + 0 gets to be 8570, right? And putting strlen inside a loop here is just for testing purposes, right? You would never put strlen inside a loop in your final program, right? Promise?;P
Anyway, I can't see anything "wrong" with the code (except that you didn't put it into pre-tags which greatly improves readability ). I put it into my VC++6.0, and got pp. 4200 ms for both lines and app. half for each of the lines alone - all in debug builds. In release builds all timings were 0 msecs.
My best shot would be that optimization is playing you a trick. Are you sure all optimizations are turned off? Or perhaps some of your other code only forces the optimizer to keep the code when both lines are present.
I'm probably wrong, but hey, that's the story of my life.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I think that Visual C++ does some trivial optimisation even in debug builds.
When line 0 is deleted, it is trivial for the compiler to know that line 1 does nothing and the the whole loop is useless.
For the other case (line 1 deleted), I don't see how it can be "optimized" except if intrinsic inline functions are enabled.
The best thing to do is to take a look at the assembler code while debugging. You will see what the compiler has generate.
At first, I would think that the compiler has detected that the loop is useless when timing is really near 0ms.
Probaly when you have both lines, the complexity is higher than what VC will try to optimize...
Philippe Mori
|
|
|
|
|
Hi.
I am becoming more familiar with Win32 API especially for winsock and core Windows including threads, processes, and DLL. I began learning programming about a year ago and my first and currently more proficient language is C++. I have no prior programming experience and not knowledge of C. Nonetheless, Win32 API and other Windows programming tools as well and good DOS and linux programs all make use of C run-time library.
I would like to know ways to allocate and deallocate a chunk of memory space. In C++, I am familiar with the new and delete operators. However, you have to define the data type you before allocating memory. I C, I believe you can allocate a chunk of memory (BYTE data type?) and store anything there. Furthermore, you can use function, I believe free(), to free the memory.
What are some ways to allocate/deallocate memory using C/C++ other than new/delete?
Thanks,
Kuphryn
|
|
|
|
|
void * ptr = malloc(NumberofBytes);
There is also calloc, and GlobalAlloc
Look 'em up to see the usage.
|
|
|
|
|
C : malloc, realloc, calloc, free
C++ : new, delete, GlobalAlloc, GlobalFree, LocalAlloc, LocalFree...
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Okay. Thanks.
Wow. I have not seen GlobalAlloc, GlobalFree, LocalAlloc, or LocalFree in my limited experience using C++. I think the only book that goes over them is by Bjarne Stroustrup.
Kuphryn
|
|
|
|
|
GlobalAlloc, LocalAlloc etc are actually part of the Win32 API, NOT the C++ language - they can be used from any language that can call a function just about (Visual Basic anyone )
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Stuart Dootson wrote:
ForumVisual C++
Subject:Re: Memory Allocation :: C/C++
Sender:Stuart Dootson
Date:2:44 15 Aug '02
GlobalAlloc, LocalAlloc etc are actually part of the Win32 API, NOT the C++ language - they can be used from any language that can call a function just about (Visual Basic anyone )
every 5th vb instruction is appended with one of these
Rutger Ellen
|
|
|
|
|
|
Is there a way to send send messages to controls in an HTML view?
I want to display a page and programmatically emulate button clicks
on controls and links etc.
Happy programming!!
|
|
|
|
|
Does anybody know of an easy way to change the font color of Static Text within mfc dialogs? It seems such a trivial thing to do, yet I have not yet found a way of doing it...
Thanks for your help.
Steve.
|
|
|
|
|
|
My code is completely unicode enabled using the _TCHAR style macro's. However, when I type Japaniese (or any other double byte characters for that matter) my dialogs still show the corrupted single byte text.
Can someone direct me to documentation or give me a tip on how to get edit controls, lists boxs, etc. to show the proper dbcs character sets?
The build I tested on was using both #define UNICODE and #define _UNICODE
This is my first attempt at making an app that supports dbcs characters, so I appologize if this is a basic question.
Thanks!
. djrisc .
|
|
|
|
|
I forgot to include that I also tried to use #define _MBCS
This generated some compiler issues due to type definition changes. However, this kind of boggles me since both ASCII and UNICODE works smoothly.
. djrisc .
|
|
|
|
|
You need to change the font in the dialog resource to "MS Shell Dlg". VC 6 sets it to "MS Sans Serif" which doesn't have DBCS support. Sadly, you'll have to change the font name every time you change the resources, because VC 6 doesn't understand Shell Dlg and will reset it back to Sans Serif.
--Mike--
Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Mike,
Perfect! Thanks a million! Worked like a charm.
. djrisc .
|
|
|
|
|
Does someone have some sample C++ programs (Visual C.NET) that do some real simple dialogue interface to a DOS program ?
I have a command line DOS C++ program that opens an input file (fopen()) reads it, manipulates it and writes it out using the same file name but in a different directory. Also, there can be some input required by the user during the processing.
I need a dialogue window that browses for a file name, followed by a dialogue that browses for a directory path (output directory) and can pass these values to my program. Also the ability to trigger a dialogue during my processing.
I am overwhelmed by all the examples provided by microsoft, when all I need is this !
Do any of you seasoned Windows C++ programmers have a shell that I can work with ?
Any comments or advice welcome
Thanks
|
|
|
|
|
I am buildng a COM dll that uses C++ dll. When registering the component C++ gives me an error - unable to locate a C++ dll (although compiling and linking were fine). How can I modify Project setting or environmental variables to tell RegSvr32 where to look for the dll?
Thanks,
This is the error I am getting:
Performing registration
RegSvr32: LoadLibrary(".\Debug\MyCOM1.dll") failed.
GetLastError returns 0x0000007e.
OleMainTreadWndName: RegSVR32.exe - Unable to locate DLL
|
|
|
|
|
That's a known error. Don't forget that depending on what libraries you link with, the DLL when loaded for registration may be automatically trying to load sister dlls, and in this case may not find one of them.
For instance, if you link with winwin.lib with at least one method implementation taken from it (_dllimport), and winwin.dll does not exist, then registration fails.
The error message tells you that's about the main dll, while it's not !
|
|
|
|
|
Hi All,
Anybody know of a way to get the interface of an existing in-proc ATL COM object that has been cocreated in a separate process? I know the name of the .exe that has an instance of the object, and I would like to grab the interface pointer to the existing object to register for events.
Thanks in advance,
Aaron
|
|
|
|
|
Option 1 : writing code properly
Looks like you should use COM aggregation. In other words, the .exe must republish the interface published by the ATL COM object.
ATL provides good classes for this purpose (CInnerUnknown, InternalQueryInterface(), ...).
Of course it assumes that you are able to recompile the .exe
|
|
|
|
|
Option 2 : use dirty windowing
Nothing prevents you to add windows messaging between your client .exe and the other .exe.
For this purpose, all you have to do is, inside the ATL code, create and attach a unique window when the ATL COM object is created and attached to the .exe
And then, from your client .exe, just find this window (::FindWindow(...)) and start doing ::SendMessage() to it.
That's dirty coding, but that's how a lot of software work on Windows.
PS : windows messaging is fine for event subscription.
|
|
|
|