|
Well, it's a little unclear from your previous post exactly what/where the problem is, so more details would be helpful. If what you're saying is that the cpu shoots to 100% utilization for 2-3 seconds each time you make a call to your math library dll (assuming it's not your code but a third party add on), then you're screwed - call their tech support and see if maybe there's something incorrect in how you're calling it. Yeah, I know, not the answer any of us ever want to hear, but if that's the case then you have to talk to the people who wrote that code.
If the dll you're calling is your own code, then of course you can look for tight looping in the dll function that you're calling.
If the problem is not 100% cpu utilization for 2-3 seconds every time you make that dll call, could you please be more specific about what you're experiencing?
Chistopher Duncan
Author - The Career Programmer: Guerilla Tactics for an Imperfect World (Apress)
|
|
|
|
|
Thank you.
I have some simple questions:
1. How to change a tight loop into a loose one?
My codes:
for (int i = 0; i < nTimes; i++)
{
Mathmatics call(); // 100% CPU utilization for 2-3 seconds per call. It's from a third party.
}
2. What I want to do is just lowering this thread's CPU utilization or making it run background. What shall I do?
3. Can suspended mode thread work?
4. If all of above failed, any further suggestion for me or the 3rd party?
|
|
|
|
|
RichardWdy wrote:
1. How to change a tight loop into a loose one?
My codes:
for (int i = 0; i < nTimes; i++)
{
Mathmatics call(); // 100% CPU utilization for 2-3 seconds per call. It's from a third party.
}
Try this:
for (int i = 0; i < nTimes; i++)
{
// you're screwed for 2-3 seconds, but...
Mathmatics call();
// this will give the other threads a fighting chance
Sleep(0);
// if you're using overlapped i/o and want your
// thread to be alertable, you'd use SleepEx(0, TRUE);
}
RichardWdy wrote:
2. What I want to do is just lowering this thread's CPU utilization or making it run background. What shall I do?
Use AfxBeginThread instead of beginthread to kick off your thread - one of the parameters is the priority, which defaults to THREAD_PRIORITY_NORMAL.
RichardWdy wrote:
3. Can suspended mode thread work?
I'm not really sure what you mean by this, but you can start the thread in the paused state by using the CREATE_SUSPENDED flag, and then call ResumeThread() when you're ready to let it go. Use the thread handle in the CWinThread* that you get back in the call to ResumeThread() or any other thread API, e.g. ResumeThread(pThread->m_hThread).
RichardWdy wrote:
4. If all of above failed, any further suggestion for me or the 3rd party?
From the looks of that for loop, there's at least the possiblity that the problem is not in the math call. A loop like that is going to redline the cpu all on its own. Try putting that sleep in there first and see if that solves the problem. If the math call truly is causing 100% cpu utilization for 2-3 seconds, it's a tech support issue. However, if it's a small enough company that you can talk to the developers, you might suggest that they too implement some Sleep(0) calls to give up the cpu periodicially. By the way, Sleep(0) seems like it wouldn't pause at all, and it doesn't. What it does, however, is tells Windows that you're thread is ready to give up the rest of its time slice to the next waiting thread, kinda like Yield() in the old 16 bit Windows days.
Hope this helps!
Chistopher Duncan
Author - The Career Programmer: Guerilla Tactics for an Imperfect World (Apress)
|
|
|
|
|
Like Chris said, just set the threads priority low. IMHO, there is little point in playing games with Sleep. Just set the priority of the thread low and let the OS do it's job. If nothing else requires CPU, the math thread will get 100% of CPU which is exactly what you want. There is no point sleeping the thread when nothing else needs the CPU. However, since the thread has a lower priority, if pratically any other thread requires the CPU, they will get it.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I remember I have seen some really indepth articles on DLLs, all the types and also when to auto load and when to load it explicitly. However, I searched Codeproject and did not find too much. I want to make my FIRST attempt. I want to include a class and ALL its resources in a DLL. Can anyone point me to ALL the articles?
I also read that when you change or add to a DLL then you have to recompile everything and relink. Is this also true if you are only changing an internal functions but not its calling method. I mean f(x,y,z)... This stays the same. Only now it is x-y+z instead of maybe x+y+z. Will this tpye of situation require the not only redistributing the DLL but also a new exe?
Thanks in advance.
|
|
|
|
|
As for the first question, do a search here at CP, there are some articles that will help you get started.
With respect to your second question: What you call "its calling method" is usually referred to as the signature of the function. You can see the set of signatures exported by a DLL as a contract between the DLL and the programs using it. Everything will be OK as long as the contract is respected by both parts. The following situiations can arise:- You preserve the signature of the exported functions but change its internal implementation: programs won't broke if the observed behavior of the exported functions stays more or less the same. For instance, if you rewrite a function to improve its efficiency. In this case, you'll need to redistribute the DLL only.
- The signature of the exported functions change: For instance, you change a
f(int) to be a f(double) . In this case you have to rebuild the programs using the DLL and resdistribute bouth the DLL and the EXEs affected.
- You maintain the signatures of the functions exported and add new functions to the DLL: old programs will work OK regardless of whether they're using the old or the new DLL. Programs taking advance of the new functions will need the new DLL, of course.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
The Subject tells you what I'm asking for.
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
What's your IP? I'll try pinging it from here.
Some ISPs block ping at the gateway though...
Nish
Oh, I don't know why she's
leaving, or where she's gonna go
I guess she's got her reasons but I just don't wanna know
'Cos for 24 years I've been living next door to Alice
24 years just waitin' for a chance
To tell her how I feel and maybe get a second glance
Now I gotta get used to not living next door to Alice
|
|
|
|
|
Check out Shields Up. It provides a quick test to see if any servers on your computer respond and it will also tell you which ports are open.
Josh Knox
that-guy.net
"Before you criticize someone, walk a mile in their shoes. That way, when you criticize them, you're a mile away, and you have their shoes." - author unknown
|
|
|
|
|
If you want to do it from a program, it's not possible. There's no way to know if there's a firewall or router filtering away access to your IP.
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
hi,
What exactly are call back functions?
Mila
|
|
|
|
|
They are handler functions for an event.
The call backs will have a pre defined prototype.
We write a function using this prototype and pass it to some other function. Now whenever some particular event occurs or some message is sent or something like that, the call back function is called for each such event.
Nish
Oh, I don't know why she's
leaving, or where she's gonna go
I guess she's got her reasons but I just don't wanna know
'Cos for 24 years I've been living next door to Alice
24 years just waitin' for a chance
To tell her how I feel and maybe get a second glance
Now I gotta get used to not living next door to Alice
|
|
|
|
|
hi
when i use the right to left layout property in a dialog, the following error appeare:
undefined keyword or key name: WS_EX_LAYOUT_RTL
can any body help me.
Best Regards
|
|
|
|
|
I think that is a bug in VC6. The correct style to use would be WS_EX_LAYOUTRTL . Edit that by hand in the .rc file...
/moliate
|
|
|
|
|
hi
I edit this in the.rc but the error is still ocure.
Best Regards
|
|
|
|
|
Then the resource editor probably overwrites it again. Remove the style from the editor, and then edit the .rc file. Perhaps a better alternative would be to add the window style in OnInitDialog with ModifyStyleEx.
/moliate
|
|
|
|
|
I see WS_EX_LAYOUTRTL in WinUser.h
Is that a typo?
|
|
|
|
|
hi
can u send to me the WinUser.h file by Email.
|
|
|
|
|
How do you get rid of the focus to an edit box when it is the only control on a dialog. If there were other controls I could do m_OtherCtrl.SetFocus(); but it doesn't seem to work on the dialog's CWnd.
|
|
|
|
|
You cannot. If the dialog has only one edit control, it will always have focus unless you disable the control.
Nish
Yeah that's me down below
|
|
|
|
|
Can I use in DAO this SQL statement ? (now, program cant find anything :/ ) :
"SELECT * FROM [tab_product] WHERE name LIKE 'wat%' " (statement have to find all rows where name like "wat??????" )
Is here any possibility to do this ? Or Is't better to use OLE BD ?
Libor Bares
|
|
|
|
|
does somebody know how to make a proper ident lookup ?
Also i´m trying to do it in vb a c/c++ idea or snippet would be fine
Except that i have to connect to port 113 of the client i´m unsure what else i have to do
So any idea ?
|
|
|
|
|
Is there any way to "tweak" the output of the classwizard? What I want to do is add some Doxygen comments on "new class", "add member function" and so on. For example, adding a new function does something like this (header):
void myFunc(int hello);
while I would prefer this:
void myFunc(int hello);
Right now I am using a very ugly macro, that does not work very well. Can this be done in a simple way?
Thanks
/moliate
|
|
|
|
|
You should consider beatifying your macro, because modifying the class wizard to do your bidding won’t work. I tried doing something similar a few years back, and I ran into several problems:
1) The resource used to write the function implementation is the same one used to write the declaration. Meaning that you would get duplicates of any additions you make, one in the *.h file and the same in the *.cpp file. Also the one added to the *.h will have to be manually removed, as it messes with the class wizards parser.
2) The resource ‘script’ parser is not very advanced. It simply grabs the stuff out of the reswource string line-by-line without doing any validation. Take for example the following WM_SIZE handler resource;
1: OnSize
2: void
3: UINT nType, int cx, int cy
4: %1::%2(nType, cx, cy);
5:
6: %4 Add your message handler code here
Line 1 is used to name the handler, and as the display string in the class wizard.
Line 2 is the return type
Line 3 is the handler’s parameter list
Line 4 generates code that calls the handler’s base class
Line 5 adds a blank line to the code
Line 6 is that stupid comment you delete instantly
So, you could add your comment into line 2, but you’d have to enter it all on the one line. Then once you used the class wizard to inserted it, you’d have to delete the comment out of the *.h (so that you don’t confuse the class wizard’s parser) and then format the comment in the *.cpp.
If your still interested in taking a look at all of this stuff just look for the MFCCLWZ.DLL file in your Visual Studio installation directory under “Common\MSDev98\Bin”. It’s all in there, under the "STRINGARRAY" resource type.
cheers,
-Ben
|
|
|
|
|
Thanks for the clarification on how mfcclwz.dll is organized. I have fired up ResHacker and started looking at it. You are probably right about it being simpler writing a better macro, but it is nice to get a better understanding on how the classwizard works!
Cheers
/moliate
|
|
|
|