|
This has nothing to do with a DLL or functions within a DLL. A beginners book on C++ would help you immensely though.
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
You already got your answer but I'll give you a quick explanation why you have this problem.
Declaring a class method as static means that the method is not called in the context of a specific class, meaning that it is very similar as a global function (it is not associated with a specific class instance). The difference between a static and a non-static method is that for a non-static method, an implicit paramater is passed to the method when it is called: the this parameter, which identifies which class instance is associated with the call (so, when you do something like that: myClass.myFunc() , the address of myClass is passed implicitely to the function). For a static method, this is not the case, since it is not associated with a specific class instance. So, within a static method, there's no accessible class instance which can be passed as the implicit this parameter passed to the non-static method. That's the reason why you can't call a non-static method from a static method (unless you call it on a class instance like this: myClass.myFunc() ).
|
|
|
|
|
Neat, sir.
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
I think your explanation confuses class with an object of class , and will perhaps confuse the OP. The this parameter is a pointer to an object and does not directly identify which class is associated with the call.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
You're right, I forgot an "instance" somewhere. I fixed it.
|
|
|
|
|
When process exit, will the memory that's left undeleted be returned to OS? My application is a C++ application.
|
|
|
|
|
Yes.
And JFYI, OS always reclaims memory after the process (application) exits. If your process runs for some time and doesn't care to release unwanted memory then it won't be reclaimed by the OS and the memory "leaks".
|
|
|
|
|
If your process runs for some time and doesn't care to release unwanted memory then it won't be reclaimed by the OS and the memory "leaks".
This part of your reply is confusing, does it mean that if I allocate memory in my program but fail to release it properly during application exit / if the application has crashed / terminated from the task manager, will this allocated memory (allocated during program execution) will not be returned to the OS and result in memory leak?
Thanx in advance
|
|
|
|
|
No no. Suppose you have a code like this in your app
void main()
{
while(true)
{
int *array = new int[100];
}
}
As long as the app runs, you will have memory leak since you aren't deleting the allocated memory.
And it doesn't really matter if the app crashes or ends normally, for the OS the app has ceased to exist and it cleans up. It is your (the app's) data files, network connections etc that would encounter trouble when the app crashes.
Clear?
|
|
|
|
|
Yes, so to my understanding, all the memory allocated using new when a process is running is allocated from the process memory heap and it will be eventually reclaimed by the OS once the process terminates.. right?
|
|
|
|
|
vipin_nvk wrote: Yes, so to my understanding, all the memory allocated using new when a process is running is allocated from the process memory heap and it will be eventually reclaimed by the OS once the process terminates.. right?
Right!
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
You could read these couple of very good essays:
Inside memory allocation[^]
Memory damage primer[^]
They aren't particularly explaining how the OS reclaims the resources after a process exits, but nevertheless they make a great read.
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
|
vipin_nvk wrote: Thanx Rajesh
Ah, how very refreshing to see a polite member. Have a 5 vote from me.
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
Bleedingfingers gave you the correct answer.
vipin_nvk wrote: My application is a C++ application.
The language used to build your program is irrelevant. The OS will ALWAYS take it back after your program is done!
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
In addition to other answer, I just wantewd to say that it is very good practice to always release the memory you are using. This will reduce the risk of memory leaks you will have when the application is running (see another answer about memory leaks).
|
|
|
|
|
Even if the OS will reclaim the memory, it's no excuse not to clean up yourself.
M.
Watched code never compiles.
|
|
|
|
|
Always clean up your allocated memory. Even though the OS will reclaim the allocated memory, deleting objects (C++) might have important side effects, such as releasing resources in other processes the instance has allocated on construction. This might lead to 'leaks' in other running processes. Also, if you don't properly delete allocated resources, your code will not be reusable in other applications. Cleaning up your own mess is an important part of C++. Clean up.
|
|
|
|
|
Hi all,
in my application i have generate so many threads but some time AfxBeginThread return NULL please tell me how can i identify why its return NULL.
here i m also try GetLastError() but its return "The Operation Completed Successfully"
please help me for this.
thanks in advance.
|
|
|
|
|
I'd recommend that you set a conditional breakpoint, and try to look at the call stack to see what caused the failure.
I hope you know that MFC comes with source code.
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
Le@rner wrote: n my application i have generate so many threads but some time AfxBeginThread return NULL please tell me how can i identify why its return NULL.
It appears to me that you are generating threads "as required" in your program. Am I wrong? If not, on what conditions do you attempt to create the threads?
Also, please post the relevant portions of the code. The way you are creating the threads, I mean the way you are calling the AfxBeginthread(...), could hold a clue.
|
|
|
|
|
int in_num=0;
std::map<int, CTest_Thread*> assocs_th;
assocs_th[in_num] = (CTest_Thread*) AfxBeginThread( RUNTIME_CLASS(CTest_Thread), THREAD_PRIORITY_NORMAL, NULL,CREATE_SUSPENDED, NULL);
if (NULL != assocs_th[in_num])
{
assocs_th[in_num]->ResumeThread();
in_num++;
}
else
{
AfxMessageBox("Error");
}
|
|
|
|
|
1, How many such threads are you actually creating?
2, Are you in need of UI threads or worker threads?
3, Are you aware that you are actually creating UI threads?
4, Have you setup a breakpoint and stepped into the code while it fails as I pointed out earlier?
Also, what's the point of having an int in_num and incrementing it, because neither is it declared static, nor is it running within a loop where the incrementing happens.
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
OK but you didn't answer the first part of my post. My questions are basically same as Rajesh's. Without knowing about those, it would be very hard for anyone to help.
|
|
|
|
|
you ask:"It appears to me that you are generating threads "as required" in your program."
yes i do
|
|
|
|