|
Jothi.G81 wrote: Before execut my application the task manager shown 498 threads
after that my application will create upto 2448 exactly, so totally 248-498 = 1950 threads created by my application.
Rather than do all of the math, why don't you just click on the Processes tab and look at the Threads column for your process?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Jothi.G81 wrote: May i know the reason about this error
The reason is that knowing how to start a thread is not the same as knowing how to create multi-threaded applications. Clearly you know the first but not the second.
|
|
|
|
|
You did start a lot of threads? Arent this TOO MUCH so you runs out of memory?
Make a debug break before you start a new thread.
Greetings from Germany
|
|
|
|
|
Hello,
The default stack size for each thread is 1MB, 32-bit Windows is capable of supporting up to 4 GB of system memory, with up to 2 GB of dedicated memory per process.
1986 * 1MB == 1986MB
The parent process is probably using the remaining memory. Which means you are at the limit of addressable memory per process.
You can possibly fix this.
http://msdn2.microsoft.com/en-us/library/ms682453.aspx[^]
Call CreateThread() to make your threads, pass STACK_SIZE_PARAM_IS_A_RESERVATION as dwCreationFlags and put 524288 as stacksize. This is (512 kilobytes)
Might look something like:
pMyThread = new MyThread();
if(NULL != pMyThread)
{
if (!pMyThread->CreateThread(CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION ,524288,NULL))
{
delete pMyThread;
pMyThread=NULL;
}
else
{
pMyThread->ResumeThread();
pMyThread->m_bAutoDelete = TRUE;
::PostThreadMessage(pMyThread->m_nThreadID,WM_THREAD_START,0,0);
}
}
Creating your threads this way could double the amount of threads available to your process.
-Randor (David Delaune)
|
|
|
|
|
Randor wrote: The parent process is probably using the remaining memory. Which means you are at the limit of addressable memory per process.
Very true David.
This also explains why he gets an access violation: he's dereferencing a null-pointer that he probably got when trying to allocate memory, but since there's no more memory he didn't get any and he didn't bother to check.
Regarding your advice of how to create more threads for the process, I doubt it would help since he apparently doesn't have a clue of how many threads he creates. He's probably got a routine that creates new threads forever until it fails. Showing him how to be able to create more threads only postpones the crash.
Tomorrow you'll find a new post asking why his application crashed after it has created ~3.900 threads....
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
A menu item which will be processed in CMyApp.
Now I want to add a hotkey F7 for this command.
In CMyView::OnKeyDown, I add this:
if (nChar==VK_F7) {
PostMessage(WM_COMMAND,MAKEWORD(ID_VIEW_TYPE,0),NULL);
return;
}
It doesn't work. How to do?
|
|
|
|
|
Go to resource editor, first option "accelerators", create it there. So it will be "global"
If you do it as you are doing it, will only valid in that view.
Greetings.
--------
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
|
|
|
|
|
Thanks very much.
I shrink my code a lot.
|
|
|
|
|
Hi all,
I used to declare a global variant, which has vector as type.
i put in the Stdafx.h :
<br />
extern vector < int > VectIter; <br />
and it myProg.cpp :
<br />
vector < int > VectIter;<br />
But when i compile i had errors like :
error C2143: syntax error : missing ';' before '<'
So, how could i fix it. (i already included the vector header #include <vector>
"The Ultimate Limit Is Only Your Imagination.
|
|
|
|
|
Did you add a #include <vector> in your stdafx.h ?
Did you forget to add using namespace std; or add the std:: before vector < int > VectIter; ?
|
|
|
|
|
yeah sure, i put on my StdAfx.h
<br />
#include < vector ><br />
extern vector < int > VectIter; <br />
and on my Prog.cpp
<br />
#include < vector ><br />
using namespace std;<br />
vector < int > VectIter; <br />
BUT the error still remains
"The Ultimate Limit Is Only Your Imagination.
|
|
|
|
|
in stdafx.h, change the declaration line with this:
extern std::vector < int > VectIter;
|
|
|
|
|
i changed it to extern std::vector < int > VectIter; and i had 12 Errors.
So i think that i will keep my first declaration.
but i read on net that VC6 generates errors even if the code is right like
<br />
std::set<int> s;<br />
std::vector<int> v(s.begin(), s.end());
<br />
std::list<int> l;<br />
l.sort(std::less<int>());
<br />
truct A<br />
{<br />
void Func()<br />
{<br />
}<br />
};<br />
<br />
std::vector<A> Tab;<br />
std::for_each(Tab.begin(), Tab.end(), std::mem_fun_ref(A::Func));<br />
So whazuuup. what should i do. i Need Vector type
"The Ultimate Limit Is Only Your Imagination.
|
|
|
|
|
Blood_HaZaRd wrote: i changed it to extern std::vector < int > VectIter; and i had 12 Errors.
So i think that i will keep my first declaration.
you shouldn't think so. firstly because you're not really understanding all that you're doing, but also because the number of errors is not relevant.
sometimes, you can have the compiler complaining about more than 50 errors, and just because you forgot a ";" in a header included in many files, you fixed all in a flashlight.
why don't you post a relevant piece of code, and tell us what are the compiler errors returned ?
(no matter if your Visual Studio is speaking french, I'm french, so i still can help).
btw, be careful when posting code involving templates, because the < > characters are understood by the browser as html tags...
-- modified at 7:45 Thursday 29th November, 2007
so, for your compilations errors, here is what i suggest you to do:
in stdafx.h, only add this:
#include <vector>
extern std::vector<int> vec;
then, in every place you need the vector class, prefer using std::vector<int>
|
|
|
|
|
Or have about 120 error for just a closing bracket "}" :P (I do know )
Greetings.
--------
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
|
|
|
|
|
Your stdafx.h gets compiled first. So put the "using namespace std" in stdafx.h
Change it as follows in StdAfx.h
#include < vector ><br />
using namespace std;<br />
extern vector < int > VectIter;
and in Prog.cpp
#include < vector ><br />
vector < int > VectIter;
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
no, definitely don't declare using the whole std namespace within stdafx.h !!!!!
|
|
|
|
|
toxcct wrote: no, definitely don't declare using the whole std namespace within stdafx.h !!!!!
why, i shouldn't do that ?
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
because you're leading to name collisions.
your can confuse the compiler with 2 classes which have the same name, just because it doesn't know to search whether the std:: namespace, the glogal one, or another namespace you just import entierely.
it's commonly accepted to avoid the using namespace std declaration, but if you really need it, then don't do it in a header file (and worst in stdafx.h, because the entiere application includes it !!!).
prefer using namespace std inside shorter scopes like functions
|
|
|
|
|
Great here it comes.
Thank you. it works now. O errors.;)
"The Ultimate Limit Is Only Your Imagination.
|
|
|
|
|
having the code compiling doesn't mean it's very clean. let's continue on our first investigation, if you like so.
|
|
|
|
|
toxcct wrote: having the code compiling doesn't mean it's very clean. let's continue on our first investigation, if you like so.
yeah sure. let's Continue on our First investig. But i hope that it runs
"The Ultimate Limit Is Only Your Imagination.
|
|
|
|
|
Hi all,
int nLen = onlyFName.GetLength();
LPCSTR lpszBuf = onlyFName.GetBuffer(nLen);
compiling this code in VC2005 gives this error:
error C2440: 'initializing' : cannot convert from 'wchar_t *' to 'LPCSTR'
|
|
|
|
|
Why do you need a LPCSTR ?
I mean, you have several options:
(1) Make an ANSI build of your code instead of a UNICODE one (default on VC2005). And your code will compile.
(2) Use LPCTSTR instead of LPCSTR , and probably, your code will be happy with this (since it is a UNICODE build).
(3) If you try point (2) and it doesn't work (maybe there is explicit use of ANSI functions in your code) the you have to convert the wide-character string to the ANSI counterpart
(may use WideCharToMultiByte for the purpose).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
neha.agarwal27 wrote: LPCSTR lpszBuf = onlyFName.GetBuffer(nLen);
Since VS2005 defaults to Unicode, simply change LPCSTR to LPCTSTR instead.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|