- Home /
Read and write to huge files
I need the ability to read and write to huge files without reading ALL of the lines and opening ALL of the lines. I need 10,000,000,000 floats to use real time, but I can't do float[] terrainVertices = new float[10,000,000,000] simply because of memory issues. I thought to myself I can read and write to a file, but theres no way without reading all data from file and that calls for creating an array of loaded data into an array(back to square one). I found out about memorymappedfile and I thought all my problems were solved until it turns out it was a .net 4.0 and above feature. Is there any solution in the current mono version or is there any way i can use memorymappedfiles in the current version or upgrade to 4.5 inside unity?
Answer by karljj1 · Apr 18, 2015 at 10:47 PM
You don't need to read the entire file if you only want a sample of the contents. Providing you know where in the file your data is then you can seek to that position and read at that point. If your file contains nothing but floats then its easy to know where in a file you need to seek to e.g index * size of float(4)
Use the seek function. http://www.dotnetperls.com/seek
Can you give me an example on how to read and write using seek. I want to read and write to a specified line in txt file. I looked up "how to read and write one line" and all the answers simply said you cant without loading and saving the whole file again.
Your storing your floats as strings? That will make it harder to know where in the file to look as a string version of a float is not a fixed size like a binary version.
Here's a link http://forums.asp.net/t/1530644.aspx?How+to+insert+update+a+text+file+content+in+C+
I now understand what you are talking about, I used to just load everything from txt file but now im understand how to use stream and its features and it has everything I need. Thanks a lot :)
Your answer
Follow this Question
Related Questions
[Closed] Place to store user data 1 Answer
trying to store to json 1 Answer
Loading a saved Game 1 Answer
How to add existing xml file to project build? 1 Answer
When writing a txt file, it says sharing violation 3 Answers