Saving very larg 3 dimensional array with BinaryFormater and FileStream causes indefinite hang in Unity
Hello,
I'm attempting to save a VERY large 3D array. Saving & Loading both work when the size is small in scale so I know my code is good on that but when I scale the array to fit my needs 24,000,000 elements exist in the array. 400x150x400. Like I said it's working fine at small scale but at large scale it just hangs and never recovers nor output any error or information.
For Reference:
private void SaveGrid()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/navGrid.dat", FileMode.Create);
Node[,,] data;
data = grid;
bf.Serialize(file, data);
file.Close();
}
private void LoadGrid()
{
if (File.Exists(Application.persistentDataPath + "/navGrid.dat"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/navGrid.dat", FileMode.Open);
Node[,,] data = (Node[,,])bf.Deserialize(file);
file.Close();
grid = data;
}
}
I have no idea how large the data is in bytes so I can't say. If somebody knows how to check a variables size in memory please do tell.
Anyhow, is there something I need to add to account for large file. It seems silly this is killing the process as it's just an array[,,] but obviously the computer knows something I dont.
Anything would be greatly appreciated.
Your answer
Follow this Question
Related Questions
Save/Load Data Android device , Unity , C# 0 Answers
How to save player score? (C#) 0 Answers
How do i Make this saving system apply the save data in my game. 0 Answers
[Error:] Cannot Deserialize JSON to new instances of type ' X ' 1 Answer
How To Save and Load player position using Serialization? 0 Answers