|
when you use the wizard to generate some code (add of a new event handler for example), it includes in the cpp file modified the related header.
the .\ means that the header - by its relative path that it - is located in the same directory as the cpp.
but this is a bug of the environment. it is useless...
you can without problem delete this #include ".\addsectordlg.h" because the file is already included the line before...
|
|
|
|
|
i hv created a thread. the cpu percentage during this time is 100%.
Any alternate soln for these.
|
|
|
|
|
What are u doing inside that thread....?
Put some sleep...
nave
|
|
|
|
|
Naveen R wrote: What are u doing inside that thread....?
Put some sleep...
Very bad advice for "solving" CPU usage problems in threads. It never resolves the underlying cause of high CPU usage. And how long should the thread sleep? 10 ms is probably the smallest quantum that can be gotten, and that might be too long to be responsive in some cases. And in other cases 10 ms isn't nearly long enough. So any choice is completely ad hoc, made as a result of some testing on the developer's machine for conditions that might not be valid on the user's machine.
In my experience, the presence of Sleep() in a thread, with the possible exception of Sleep(0), is generally a bad design choice.
Best regards,
Mike
|
|
|
|
|
Threads, like any other process, will take up as much CPU as there is available. If you're doing pure processing in a separate thread, there's not a lot you can do - you can reduce the priority of the thread but this will only reduce the CPU time if other processes are running too.
I suspect more likely you're writing code like:
void MyThread()
{
extern volatile bool isThereAMessage;
while (!isThereAMesage) { }
...process message...
}
This type of behaviour, spinning in a loop waiting for something to happen, is a frequent cause of threads taking up all available CPU time. If you are in this kind of situation, then I suggest you look at your OS's thread synchronisation and wait functions. If you're on windows, WaitForMultipleObjects, WaitEvent and similar. These put your thread to sleep until a message (or timeout) occurs, releasing the CPU for other processes to use it.
[NB the code example I have above is it itself not strictly thread safe; instead of using pure volatile bools, one should use thread safe calls, for example the Win32 InterlockedIncrement() and InterlockedAdd() etc]
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
[quote]
Threads, like any other process, will take up as much CPU as there is available
[/quote]
it is definitely incorrect.
at least, when process which creates the thread is active, the thread is sleeped, I think other processes can sleep any thread.
Priority.
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
-- modified at 3:17 Friday 7th April, 2006
|
|
|
|
|
I said as much CPU as there is available to that thread - which is correct as far as I understand. The operating system will split up the CPU time amongst all threads, taking into account thread priority, temporary active window priority boosts and other factors. When you create a thread, unless you specify CREATE_SUSPENDED as a parameter, the other thread will start running immediately. On a multi-processor system that can mean both the parent thread and its child are running concurrently - something to watch out for.
Threads are only slept when they're waiting on an object or they've called 'Sleep()' themselves. In all other cases, even when they're not actually running, the thread is in the 'Ready' state, so the OS will schedule them for running as soon as it can. Thus, a thread will take up as much CPU as there is available.
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
The while loop is doing a busy wait - A big no no on multitasking operating systems. Use something like this:
HANDLE g_ThereIsAMessage = CreateEvent(NULL, FALSE, FALSE, NULL);
SetEvent(g_ThereIsAMessage);
void MyThread()
{
for( ; ; )
{
WaitForSingleObject(g_ThereIsAMessage, INFINITE);
}
}
Steve
|
|
|
|
|
To me, any code EVER waiting INFINITE is a big no-no
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
The code was only meant as an illustration of how to do a wait that isn't busy - Obviously in a real application you would use a call to WaitForMultipleObjects and have multiple events one of which would be an exit event.
Steve
|
|
|
|
|
That was my exact point; hence my message explaining how to do exactly as you describe!
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
Syncronize your thread.
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
Hi,
I have created IDC_LIST (list box) of type ClistBox and Member m_list.
For Add items I am using m_list.AddString(szDir); & for reset the list I am using m_list.ResetContent(); both this are working fine.
Can anyone tell me how to delete a item from list ? if I have 5 items in my list box if I have selected 4th item in the list box after pressing delete button I want that 4 item to be removed from list how to do that ??
And also I want to access all items of the list box in other functions.
Regards,
Parichay B.P
|
|
|
|
|
Hi parichaybp ,
for delete from ListBox use DeleteString
|
|
|
|
|
m_list.DeleteString();
its working but i want to know how to remove the selected item?? what parameter have to passed ??? how to access the selected item and remove it??
and plz also tell how to access all the list items???
|
|
|
|
|
use DeleteString() if u want to delete an item from the list.
To get the index of currently seleted item use GetCurSel()...
m_list.DeleteString( m_list.GetCurSel() );
if u want to get all the items in the list .....
int nCount = m_list.GetCount();
for(int nIdx = 0;nIdx< nCount;nIdx++)
{
CString csText;
m_list.GetText( nIdx, csText ); // u will get the text in csText
}
nave
|
|
|
|
|
|
///////This example for Delete/Insert / read and count And Create
//But you dont need to create list becuase you have control in your form
CListBox m_List2;
m_List2.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,100,100),this,1);
m_List2.AddString("1");
m_List2.AddString("2");
m_List2.AddString("3");
m_List2.AddString("4");
//For Delete from ListBox
m_List2.DeleteString(0);//Delete 1//m_List2.GetCurSel()
//////For GetItems
CString Str,temp,Str2,Str3;
CStringArray m_String;
for(int i = 0;i< m_List2.GetCount();i++)
{
m_List2.GetText( i, temp);
Str.Insert(0,"\\"+temp);//insert in location 0
Str3.Insert(Str3.GetLength(),"\\"+temp);//insert in location end
Str2=Str2+"\\"+temp;//insert 1\2\3
m_String.Add(temp);//insert to array
}
|
|
|
|
|
hai ,All
In a recent interview I have faced a question ,
Whatis the difference between C and C++ structure.
krishna
|
|
|
|
|
In the simplest cases - nothing. C++ ws designed specifically so that C code will compile and have the same meaning as it does when compiled with a C compiler.
However, semantically, in C++ a structure is identical to a class, except its default access specifier is public: instead of private: . In practice therefore, a C++ structure can have member functions, operators, base classes and virtual functions, just like a class. If you're writing code to interoperate between C and C++, you may need to bear this in mind - C++ will add a virtual table pointer if you have virtual methods which the C code won't know about. Similarly if you derive a structure from a base class (or structure), there will be extra information in your structure that the C structure won't have. These are issues if you need to maintain the exact same binary format as a C program (for example, if you call C functions with pointers to structures.)
Syntactically there's a difference too. In C++ the structure name is treated as a proper type name, whereas in C the name must always be prefixed with struct . In C it's common to typedef the structure:
typedef struct tagFoo { ... } Foo;
Foo foo;
This is valid in C++, but the typedef is unneccesary. However if you want to have source code that interoperates between the two languages (ie compiles as both C and C++) you'll need to use the C-style syntax.
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
That's a really good explanation. Very clear
|
|
|
|
|
1. you can add keywords in C++: public, protected, private
2.you can add fuctions in side struct in C++;
(struct is similar to class in C++ except default members are public).
3. instance can be created directly without type struct.
E.g. if MyStruct is a struct, u can
MyStruct ms; //OK in C++ but error in C.
in C, u must say:
struct MyStruct ms;
maybe something more - inherented?.
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
-- modified at 3:00 Friday 7th April, 2006
|
|
|
|
|
If during a build that is meant to be for unicode only UNICODE is defined in the preprocessor definitions and not _UNICODE, might that have negative consequences?
Why are there 2 different definitions anyway?
Thanks for any insight in this issue..
Davy
|
|
|
|
|
GDavy wrote: If during a build that is meant to be for unicode only UNICODE is defined in the preprocessor definitions and not _UNICODE, might that have negative consequences?
Why are there 2 different definitions anyway?
_UNICODE is for TCHAR support.
More Information[^]
Nibu thomas
Software Developer
|
|
|
|
|
UNICODE is for the Windows header files and _UNICODE is for the CRT.
Steve
|
|
|
|