|
Thanks.
I did read it before posting my question here but I didn't find any reason for my error.
Toe the line
Thread the needle
Think outside of the box
|
|
|
|
|
Probably you have to post the relevant code.
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.
|
|
|
|
|
Another dialog hosts a pointer as a private data member:
ModelessDlg * m_pModelessDlg;
When creating the modeless dialog:
if(m_pModelessDlg)<br />
{<br />
m_pModelessDlg->SetForegroundWindow();<br />
}<br />
else<br />
{<br />
m_pModelessDlg = new ModelessDlg(this);<br />
m_pModelessDlg->Create(ModelessDlg::IDD, this);<br />
m_pModelessDlg->ShowWindow(SW_SHOW);<br />
}
There is a CProgressCtrl on this dialog. Does it matter if I create and display the modeless dialog without initializing the progress control? I think I should be able to see an empty progress bar on that dialog.
As an alternative, instead of using ShowWindow, I tried to set the Visible property of this modeless dialog to Yes. Then I got the modeless dialog displayed correctly (With all controls displayed including the progress ctrl). BUT another error has occurred: the modeless dialog was kind of in a No responding state for 3 seconds. Then I could move the dialog around but could not switch the focus to the parent dialog. In addition when moving the dialog around, a great number of fake dialogs were made like a tail to the original one(When happening, the available memory of my computer was still big enough)
Toe the line
Thread the needle
Think outside of the box
|
|
|
|
|
Are you doing anything in the dialog's OnInitDialog() method?
"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
|
|
|
|
|
No. I even didn't override the OnInitDialog method. I have tried to override it and only do CDialog::OnInitDialog(); in it. The situation has not been changed. The modeless dialog is stuck in a no respond state. I can't get the focus of the parent dialog.
Toe the line
Thread the needle
Think outside of the box
|
|
|
|
|
Hi,
I wrote a simple program uisng CEvent Synchronization if execute my application. the threade upto 1986 after it shows the following error
unhandled exception at 0x00418552 in WorkerThreads.exe: 0xC0000005: Access violation writing location 0x00000028.
may i know the reason
Regards
Jothi.G
|
|
|
|
|
Use your debugger to find the exact readon. It can be for so many reasons that it is impossible to tell you.
Jothi.G81 wrote: the threade upto 1986
What do you mean, you have 1986 threads in your application ?
|
|
|
|
|
Wow, 1900 threads
Why do you create so much threads ? This will bring your system to its knees and your application will spend more time switching between the threads instead of doing actual work.
And, BTW, you really should use your debugger (press F5 to start and F9 to set breakpoints).
|
|
|
|
|
with lots of threads I don't expect a debugger to be useful at all; I would make sure
ALL error conditions get checked everywhere, all anomalies and some tracing get logged,
then compare the logs of a couple of runs. That should create the possibility to
formulate some hypothesis.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
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.
then it shown a message like this
Unhandled exception at 0x00418552 in WorkerThreads.exe: 0xC0000005: Access violation writing location 0x00000028.
May i know the reason about this error
Regards
Jothi.G
|
|
|
|
|
Are you actually reading my posts ?
For your error message, it is the third time you post it, I think by now I got it .
The problem is probably because you are creating too many threads that your system can support. And then you don't check if the thread creation was successfull and suppose that everything went fine.
|
|
|
|
|
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>
|
|
|
|