G
Guest
I have created the followinga simple Managed C++ windows application with a
single button. Here is my button_onclick code
private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)
{
FileStream *myFile;
try
{
myFile = new FileStream(
S"A VERY LARGE 300 MEGABYTE FILE",
FileMode::Open,
FileAccess::Read);
}
catch (Exception *e)
{
return;
}
if (myFile != NULL)
{
__int64 myFileSize = myFile->get_Length();
Byte myFileData[] = new Byte[(int) myFileSize];
myFile->Read(myFileData, 0, (int) myFileSize);
delete myFileData;
}
}
I observe the following behavior via the Windows Task Manager
When I create the ByteArray, allocated Virtual Memory remains the same
In response to the Read statement, allocated Virtual Memory increases by the
size of the file and never decreases.
If I repeatedly click the button in my form, the virtual memory size
fuctuates. Sometimes it 1x the file size, sometimes it is 2x the file size,
or 3x the file size. Eventually, if I click the button often enough, the
application dies with an OutOfMemory exception when it exceeds 1.4 gB.
How can I force the framework to minimize the amount of Virtual Memory being
used?
single button. Here is my button_onclick code
private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)
{
FileStream *myFile;
try
{
myFile = new FileStream(
S"A VERY LARGE 300 MEGABYTE FILE",
FileMode::Open,
FileAccess::Read);
}
catch (Exception *e)
{
return;
}
if (myFile != NULL)
{
__int64 myFileSize = myFile->get_Length();
Byte myFileData[] = new Byte[(int) myFileSize];
myFile->Read(myFileData, 0, (int) myFileSize);
delete myFileData;
}
}
I observe the following behavior via the Windows Task Manager
When I create the ByteArray, allocated Virtual Memory remains the same
In response to the Read statement, allocated Virtual Memory increases by the
size of the file and never decreases.
If I repeatedly click the button in my form, the virtual memory size
fuctuates. Sometimes it 1x the file size, sometimes it is 2x the file size,
or 3x the file size. Eventually, if I click the button often enough, the
application dies with an OutOfMemory exception when it exceeds 1.4 gB.
How can I force the framework to minimize the amount of Virtual Memory being
used?