|
If I comment the foo(), that's no problem.
I am confused about it, may be it is the bug of g++?
I'm amumu, and you?
|
|
|
|
|
Hi,
I know that if there are several threads share a common array, i need criticalSection to protect to prevent all threads trying to WRITE to this array at the same time.
However, I just wonder if criticalSection is required to prevent all threads trying to just READ the info from this array at the same time.
Thanks!
|
|
|
|
|
It is not required, there is not a problem if everyone is just reading. However if you have some threads reading and other writing then you must protect yourself as well
Best regards,
Alexandru Savescu
|
|
|
|
|
Yes, because if you don't then you run the risk of reading while someone is writing and thus the data might be suspect.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
#include <iostream.h>
class a
{
public:
a()
{
cout<<"a::a"<<endl;
}
="" ~a()
="" {
="" cout<<"a::~a"<<endl;
="" }
};
class="" b:public="" a
{
private:
="" char*="" ptch;
public:
="" b()
="" cout<<"b::b"<<endl;
="" ptch="new" char[100];
="" ~b()
="" cout<<"b::~b"<<endl;
="" delete="" ptch;
="" }
};
int="" main()
{
="" b*="" ptb="new" b;
="" a*="" pta="ptb;
" pta;
=""
="" return="" 0;
}
and="" how="" about="" this="" one?
#include="" <iostream.h="">
class a
{
public:
a()
{
cout<<"a::a"<
|
|
|
|
|
The first one causes a memory leak because the destructor for class b does not get called. If you make the destructor in class b virtual, then the destructor will get called, and there will be no memory leak.
The second one does not cause a memory leak, because there is no dynamic memory allocation internal to either class.
|
|
|
|
|
I see, Thank you very much!
I'm amumu, and you?
|
|
|
|
|
Yes you need to make the class b destructor virture. The destructor for class b is wrong as well. To avoid memory leak, the class b destructor should be:
virture ~b
{
....
delete []ptch;
}
|
|
|
|
|
'virture'? Is it from Java?
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
You have to make a's destructor virtual. Once that is done, B's destructor will also by definition be virtual.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Hi
does anyone use the install-shield app which comes with VC 6.0?
Ive been messing about with it today and have a question or two
Bryce
|
|
|
|
|
Yep, what are your questions?
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
hi,
I have a application that traps the keystrokes using hooks.I want send these trapped keystrokes to another application.
Thanks in advance
|
|
|
|
|
Use SendInput (not available on Win95) or keybd_event.
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
how do you direct the keyboard event generated by keybd_event to particular window.
|
|
|
|
|
hi,
I have a application that traps the keystrokes using hooks.I want send these trapped keystrokes to another application.
Thanks in advance
|
|
|
|
|
What's the easiest way for an app to know when a machine (say, a laptop) has come out of hibernation? In CE there is the WM_HIBERNATE message but I can't seem to find a win32 equivalent.
cheers,
Chris Maunder
|
|
|
|
|
WM_POWERBROADCAST?
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
I'll give it a shot - thanks Derek!
cheers,
Chris Maunder
|
|
|
|
|
Hi,
Can anyone please give me an example of the function:
QueryPerformanceCounter()??
What I know is that it is related to "high-resolution performance...". But, I don't really know how to use it.
Thank you!
|
|
|
|
|
|
Thank you! I've actually checked that out already.
And, I've found an even simpler program about that.
|
|
|
|
|
Hi,
I just wonder if my program is really protected by CriticalSection:
My program uses multithreading......and require to access many array. Since I want to prevent same time access to an array item by several threads, I centralize all operation that modify the content of array in one function. Here is the structure of this function:
int function(....)
{
CCriticalSection cs;
cs.Lock();
//code for modifying array here....
cs.Unlock();
}
However, my thread function has some codes to "read" the array content in their own thread function.
My question is: Is it OK???
I have run my program. Sometimes OK, sometimes has error (especially i choose to run so many threads...)
Any suggestion to help me debug???
|
|
|
|
|
ChiYung wrote:
Is it OK???
NO
CCriticalSection cs; <--- this is now a temp variable
Make it a member of your class or make it global
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
Nish [BusterBoy] wrote:
Make it a member of your class or make it global
I tried to declare it in StdAfx.h and .cpp:
In StdAfx.h:
extern CCriticalSection cs;
In StdAfx.cpp
CCriticalSection cs;
But i have this error message:
"error C2146: syntax error : missing ';' before identifier 'cs'
fatal error C1004: unexpected end of file found"
What happened??
I tried to put it in ....Dlg.h...........same error.........
Can you help me!!!????
Thanks!!!!
|
|
|
|