|
OCrowley wrote: For a dual core processor running at 1.86Ghz each, on task manager it shows roughly 50% CPU usage when ONE EMPTY thread is running in a loop. [WTF]
Your system contains a lot of other system processes and services running in background which ofcourse will grab the cpu.
If you want to know the time used by your process, then take perfmon.exe and add a watch on "Processor Time" on your test application. Look here for how to use it. - http://www.windowsnetworking.com/articles_tutorials/Windows_2003_Performance_Monitor.html[^]
I thought you were asking about the processor time utilized by your process. Just ignore my reply.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
modified on Friday, June 6, 2008 1:18 AM
|
|
|
|
|
Misunderstood his question.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Your thread is an infinite loop, so it's probably eating up all the time there. I don't see where you end your thread, as it can't end itself.
You could put a
Sleep(500); in your thread, and you'll see the usage drop.
In reality a useful thread would probably be performing some function and then suspending itself until it's time to do that function again. While it's working, it'll use whatever CPU time it needs to complete the task.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Your thread is using its entire quanta/time-slice. As the previous poster said, put in a sleep or, even better, create a global event handle and wait on it, exiting when it becomes signaled.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Just to add to the previous two answers: the only reason it is not showing 100% CPU time, is that it is dual core, and only one core is assigned per thread.
|
|
|
|
|
Hi again.
I've included the sleep functions in all threads I'm using and that's done the job! Back to 0-1% again!
Thanks all for your great help!
"create a global event handle and wait on it, exiting when it becomes signaled."
I'll look into that as well. Thanks very much.
OCrowley.
|
|
|
|
|
Hi,
How can I display an .eml message in my application similar to outlook express?
|
|
|
|
|
I could found functions that solve the problem, but there is some problem with the kind of variables, first I made a cast of the name the archive, it solve but it did't with CStringArray line; to LPCTSTR
tried:
AppendLineToMultilineEditCtrl(m_Edit,LPCTSTR(line::GetData()));
It gave the error:
Error 1 error C2510: 'line' : left of '::' must be a class/struct/union c:\Users\henitz\Documents\Visual Studio 2005\Projects\CodeDecodeCPlus2\CodeDecodeCPlus2\CodeDecodeCPlus2Dlg.cpp 108
Error 2 error C3861: 'GetData': identifier not found c:\Users\henitz\Documents\Visual Studio 2005\Projects\CodeDecodeCPlus2\CodeDecodeCPlus2\CodeDecodeCPlus2Dlg.cpp 108
Thanks
void CCodeDecodeCPlus2Dlg::OnBnClickedCode()
{
// TODO: Add your control notification handler code here
if (m_Code)
{
CStringArray line;
ReadTextFile(LPCTSTR("Teste2.txt"),line);
AppendLineToMultilineEditCtrl(m_Edit,line);
}
}
void AppendTextToEditCtrl(CEdit& edit, LPCTSTR pszText)
{
// get the initial text length
int nLength = edit.GetWindowTextLength();
// put the selection at the end of text
edit.SetSel(nLength, nLength);
// replace the selection
edit.ReplaceSel(pszText);
}
void AppendLineToMultilineEditCtrl(CEdit& edit, LPCTSTR pszText)
{
CString strLine;
// add CR/LF to text
strLine.Format(_T("\r\n%s"), pszText);
AppendTextToEditCtrl(edit, strLine);
}
void ReadTextFile(LPCTSTR pszFileName, CStringArray& arrLines)
{
arrLines.RemoveAll();
CString strLine;
TRY
{
CStdioFile file(pszFileName, CFile::modeRead);
while(file.ReadString(strLine))
arrLines.Add(strLine);
}
CATCH_ALL(e)
{
e->ReportError(); // shows what's going wrong
}
END_CATCH_ALL
}
|
|
|
|
|
why are you writing LPCTSTR(...) ?
you're not calling a new type's constructor, you're calling a cast operator from an existing type.
so change into this: (LPCTSTR)... .
BTW, dunno if it's related to you issue though.
also, how is defined line ?
|
|
|
|
|
toxcct wrote: also, how is defined line ?
Locally as CString array CStringArray
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
modified on Thursday, June 5, 2008 1:57 PM
|
|
|
|
|
I corretecd first cast:
ReadTextFile((LPCTSTR)"Teste2.txt",line);
What I can do with line
It's defined like:
CStringArray line;
But the function ask: CStringArray& arrLines
AppendLineToMultilineEditCtrl(m_Edit,(LPCTSTR) line);
Ask line like: LPCTSTR pszText
|
|
|
|
|
Your function is expecting a reference
Henitz wrote: void ReadTextFile(LPCTSTR pszFileName, CStringArray& arrLines)
and you are giving
Henitz wrote: CStringArray line;
ReadTextFile(LPCTSTR("Teste2.txt"),line);
an object.
Does it helps?
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Henitz wrote: tried:
AppendLineToMultilineEditCtrl(m_Edit,LPCTSTR(line::GetData()));
It gave the error:
The problem is in the signature of AppendLineToMultilineEditCtrl() . See its signature below.
Henitz wrote: void AppendLineToMultilineEditCtrl(CEdit& edit, LPCTSTR pszText)
From name, i guess, you want to add multiple strings to edit control and you're calling the function with string array, but that function takes only a string as param. I think, you need the following one.
void AppendLineToMultilineEditCtrl(CEdit& edit, CStringArray& arrLines)
{
}
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
If did, I have to change all code of the function.
Do you how to do ?
|
|
|
|
|
I don't want to offend you, but the solution given is from basic level, if you dont know how to iterate an array... I strongly recommend you to start reading a basic manual and trying easy things at the beggining to go complicating them incrementally.
One hint:
for (intial condition; while condition; iteration)
{
//here the things that have to be repeated
}
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Stop trying to cast your problems away, it just makes things worse!
Steve
|
|
|
|
|
Henitz wrote: line::GetData()
Shouldn't this be line.GetData()?
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Hi, I am looking for some information on how to enumerate through the list of available drives on the local machine to be displayed to the user. I remember coming across something similar on CP sometime back, but I am unable to locate it now. If someone could point me in the right direction on where to find some sample code or demo progs., it would be greatly apperciated.
I am going to be doing this in VC++ (2003), MFC, on Windows.
Thanks
|
|
|
|
|
Have you tried GetLogicalDrives() or GetLogicalDriveStrings() ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Try something like this:
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
DWORD mask = GetLogicalDrives();
for (char letter='A'; mask!=0; mask=mask>>1, letter+=1)
{
if (mask & 1)
{
cout << letter << ":" << endl;
}
}
return 0;
}
Steve
|
|
|
|
|
|
|
I have a Rich Edit Control Box in my dialog based visual c++ 6 application. The Text Displayed in the REditctl is in myfont.ttf. I want to :->
1)Format Different Lines of the text in different point size.
2)The text of the REditctl should be saved alongwith formatting.
(.doc,.txt file extensions)
3)The multiline text should be printed as formatted with myfont.ttf.
I tried that so much available Printing code for dialog based application.
Can some body help and give me a simple but correct insertable code for the
above narrated 3 problems.
|
|
|
|
|
Why don't you get every different format as a different text? and in each of them say which font are you using, that will make easier to save/print datas. One suggestion (I don't even know if it is a good way to do it, but just an idea).
You can declare a class with a "header" where the font is saved and use different instances of that class according to how the text is formated
I mean... suppose a text of 10 lines, and you want to change font in lines 4 to 6, then brake your 10 lines text into 3lines (1-3), 3lines(4-6) and 4lines(7-10) text parts. So when you save the datas into a file you save the header at first place, then the content of that text part and then the next one. By printing you can use it as well, by getting the first part, looking the header and configurating the DC with that info, then send the text included to the printer and continue with the next part.
Other member will most probably have better options, but this at least is a possibility.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Hi all
I try to display current time in static control but its not given me the time its show me something
unicode values although i have changed the setting but still i did get result
Thanks
|
|
|
|