Hi all,
I’m trying to read in the contents of a file using the Method ReadStringFromFile below. When i go to instantiate the byte[] array with a size of 1245464 (thats the file size), it fails with the following exception. 1.2MB file, 6.8ish free.
I assume this is a heap problem, that’s the extent of my knowledge. Is there a work around where I can get this data in and parse it?
Thanks!
#### Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (1) ####
#### Message:
#### Redliners.PCMSimulator.Helpers.SdCardHelper::ReadStringFromFile [IP: 0033] ####
#### Redliners.PCMSimulator.Program::ProgramStarted [IP: 0013] ####
public static string ReadStringFromFile(string fileName)
{
if(Mainboard == null)
throw new Exception("Mainboard has to have a value in SdCardHelper");
string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
FileStream FileHandle = new FileStream(rootDirectory +
fileName, FileMode.Open, FileAccess.Read);
byte[] data = new byte[FileHandle.Length];
int read_count = FileHandle.Read(data, 0, data.Length);
FileHandle.Close();
Debug.Print("The size of data read is: " +
read_count.ToString());
Debug.Print("Data from file:");
Debug.Print(new string(Encoding.UTF8.GetChars(data), 0,
read_count));
return new string(UTF8Encoding.UTF8.GetChars(data));
}
GC: 4msec 481272 bytes used, 6858396 bytes available
Type 0F (STRING ): 636 bytes
Type 11 (CLASS ): 7908 bytes
Type 12 (VALUETYPE ): 1104 bytes
Type 13 (SZARRAY ): 4284 bytes
Type 03 (U1 ): 636 bytes
Type 04 (CHAR ): 648 bytes
Type 07 (I4 ): 468 bytes
Type 11 (CLASS ): 2532 bytes
Type 15 (FREEBLOCK ): 6858396 bytes
Type 17 (ASSEMBLY ): 34200 bytes
Type 18 (WEAKCLASS ): 96 bytes
Type 19 (REFLECTION ): 168 bytes
Type 1B (DELEGATE_HEAD ): 756 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 424560 bytes
Type 1F (THREAD ): 1920 bytes
Type 20 (SUBTHREAD ): 240 bytes
Type 21 (STACK_FRAME ): 1056 bytes
Type 27 (FINALIZER_HEAD ): 120 bytes
Type 31 (IO_PORT ): 108 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 3876 bytes
6858396