|
Please check whether you have properly included the staticlib in its settings. Second thing, you have to specify the path in which the static liv is located in Project->Settings->Link->Input. Also please check whether you have included the namespace of the first project in the second one.
akt
|
|
|
|
|
Hi there.
I've been messing around with programming Windows threads in Visual C++ 2008 and I just recently noticed how much CPU my computer uses when it runs only ONE thread.
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.
Can anyone tell me WHY on earth it's using so much CPU and how to solve this problem?
Is it due to how I've created and called the thread? the current code I have got is:
hThread = (void *)_beginthreadex(0, 0, &TestThread, 0, 0, &uThread);
where "TestThread" is the thread function, as shown below:
unsigned _stdcall TestThread(void *)
{
while(true);
_endthreadex(0);
return 0;
}
thanks in advance,
OCrowley.
|
|
|
|
|
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.
|
|
|
|