
The application I am writing opens a file (of variable size, but possibly large) at the start. It needs to read from this file often during execution, so I basically opened the file with CreateFile() and then left it. However, I seem to be running out of stack space later on in the program (at least I think that's the problem).
To get around the problem, I now use CloseHandle() as soon as I am done with the file, and then call CreateFile() again every time I need to re-access the data, and this seems to cause no problems.
Example (old method):
1. CFileHandler class opened file in constructor
2. CFileHandler class called CloseHandle() in destructor
The CFileHandler class is instantiated once at the beginning of my application (CFileHandler *handler = new CFileHandler()), and not destroyed until the program finishes.
Example (new method):
1. CFileHandler.ReadData calls CreateFile() at start
2. CFileHandler.ReadData calls CloseHandle() at end
3. No file handling is done in the constructor/destructor
Is this inefficient? Or is this how I should be doing things? Are there any other suggestions?
I am using eVC++ 3.0 and the PPC2002 emulator that comes with it.
Thanks![/code]