Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im busi with a proram that reads numorous text files, but the problem is that using TStringLists the memory is over used and the program tends to freeze or block out the computer speed. is the a way to do file accessing without using TStringLists, TString objects and fstreams?
Posted
Comments
Sergey Alexandrovich Kryukov 30-May-11 2:38am    
Is it VCL, it looks like?
--SA

File reading does not kill memory. Of course you don't have to use TStringList or TString to read file. If looks like you work with text files. You can read the file in one single string. The idea of reading file without fstream is ridiculous. This is exactly what you need to do. If you just read, you should use ifstream, see http://www.cplusplus.com/reference/iostream/ifstream/[^].

—SA
 
Share this answer
 
Comments
Joan M 30-May-11 3:24am    
A nice answer, as always... 5.
Sergey Alexandrovich Kryukov 30-May-11 3:29am    
Thank you, Joan.
--SA
I am assuming you work with C++Builder, as the only built-in classes called TString or TStringList I know of can be found in Borland Delphi (and C++Builder, as a quick search confirmed).

You might want to check how much memory these files might consume, and whether you have to keep them all in memory at the same time. Also, if you're building additional data structures based on what you read, check how much more memory this takes, and whether you need to keep that in memory as well.

If you're running low on memory, this is about the only thing you can do. fstream, TString, and TStringList all should be safe to use. However, if you're building additional data structures using new, make sure that you do delete them properly again when you don't need them any more. For instance if you create TStringList objects with new, make sure to call delete before reassigning the pointer, or before the pointer runs out of scope!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900