I have a simulation engine written in Visual C++ 2010 and I'm implementing a DLL plugin based on it for another 3rd party application.
However, I get a stack overflow error when my library is called by the 3rd party app's thread. After debugging it turned out that the DLL requires a bigger stack size than the thread has. Is it possible to extend the current thread's stack size somehow?
I know I should probably review the simulation engine's code and move big objects to the heap. The problem is that the engine is maintained by another vendor and I'd like to avoid modifying their code if possible.
I'm thinking about creating my own thread in the DLL with a bigger stack size and returning the results to the calling thread when the calculation finishes. Is it the right approach?
Thanks, Michal
I'm going to suggest that the first thing you check is how much stack space you're actually using. Are you allocating large objects on the stack? Does your program utilize significant recursion depths? Write a test hook application you can link into your DLL and check how much stack space you use.
If you're allocating large objects on the stack I would strongly suggest moving them to the heap.
If you're doing significant recursion you may wish to investigate using a loop with a heap-based stack maintained by your DLL rather than relying on the application's stack.
I make these suggestions simply because it's much less intrusive for a plugin to be self-contained and not require special stack configuration (or even an entirely separaate thread just to have a larger stack).