i have a confusing memory problem using multithreading with a .DLL file.
The .DLL Code is really crappy, some voodoo mathmatics stuff happens there in an infinity loop - there are also some memory leaks which i can not solve.
extern "C" __declspec(dllimport) void U_SchallMain(void* args); // include the main from my .DLL file
int main(int argc, char *argv)
HANDLE U_SchallHandle = (HANDLE) _beginthread( U_SchallMain, 0, (void *) 20 ); //start Thread
My idea was to start this Code as a Thread and restart it after a certain number of iterations in order to free the memory used by the Thread.
So far so good.
This is the Code of the DLL:
Now my problem: The Memory allocated to the Thread is not free after it calls _endthread();
int __declspec (dllexport) U_SchallMain( int cycles )
... voodoo ...
if( run >= cycles ) // stop program after number of cycles is => var 'cycles'
printf("DEBUG_U_SCHALL::Quit after %i cycles\n", run);
When I start my program it takes about 7.000K, with the Thread started it weights 14.000k and higher. After _endthread() it should be 7.000K again but it doesnt.
Is it because I am using _beginthread instead of _beginthreadex or where is the mistake?
Im using Visual Studio 2008 and compile this project as C++.
(PS. Sorry for my bad english )