H
Howard Weiss
I am reading a 160 mB file in my application. I want to access the file as
shorts. FileStream->Read wants to access the file as Byte so I do the
following
1) Read the filesize
2) Create a Byte[] array of the appropriate size
3) Read the file
4) Create a (global) nogc array of the same size and copy the data from the
Byte array to the gc array
5) Delete the Byte[] array
as follows:
FileStream *myFile = new FileStream(pPath, FileMode::Open,
FileAccess::Read);
__int64 myFileSize = myFile->get_Length();
Byte[] myFileData = new Byte[(int) myFileSize];
myFile->Read(myFileData, 0, (int) myFileSize);
int x = myFileData->Length;
pFileData = new unsigned char [(int) myFileSize];
for (int ii = 0; ii < myFileSize; ii++)
pFileData[ii] = myFileData[ii];
delete myFileData;
myFile->Close();
The code for delete myFileData sets the pointer to 0. Presumeably, this
will cause the garbage collector to reclaim the memory. Using the task
manager, I observe that the Mem Usage for my process increases by twice the
file size (over 300 mB) and never decreases (e.g. the Byte array is never
garbage collected). I have tried adding a GC::Collect() call after the
delete myFileData but nothing happens.
Any suggestions?
Howard Weiss
shorts. FileStream->Read wants to access the file as Byte so I do the
following
1) Read the filesize
2) Create a Byte[] array of the appropriate size
3) Read the file
4) Create a (global) nogc array of the same size and copy the data from the
Byte array to the gc array
5) Delete the Byte[] array
as follows:
FileStream *myFile = new FileStream(pPath, FileMode::Open,
FileAccess::Read);
__int64 myFileSize = myFile->get_Length();
Byte[] myFileData = new Byte[(int) myFileSize];
myFile->Read(myFileData, 0, (int) myFileSize);
int x = myFileData->Length;
pFileData = new unsigned char [(int) myFileSize];
for (int ii = 0; ii < myFileSize; ii++)
pFileData[ii] = myFileData[ii];
delete myFileData;
myFile->Close();
The code for delete myFileData sets the pointer to 0. Presumeably, this
will cause the garbage collector to reclaim the memory. Using the task
manager, I observe that the Mem Usage for my process increases by twice the
file size (over 300 mB) and never decreases (e.g. the Byte array is never
garbage collected). I have tried adding a GC::Collect() call after the
delete myFileData but nothing happens.
Any suggestions?
Howard Weiss