Running out of memory prematurely

Started by
3 comments, last by Kylotan 6 years, 9 months ago

Sometimes I get an out of memory exception when I don't think I should.  It's been happening when I try to write a file to the hard drive.  For analytical purposes I have to have all the data loaded into ram before writing it, and it is several dozen megabytes.

 

However, I know that I have 16 gigabytes of ram and I'm hardly running any other programs, certainly not anything that would take a significant fraction of it.  Isn't memory first-come first-serve, meaning that Windows should let me have however much I need until I've used it all and then run out?

 

Also, it oddly occurs while I'm writing the file.  The data is already in ram, and I'm not allocating any more.  I thought that the only thing that could cause that exception was a memory allocation, or am I wrong?

 

And by the way, I know that the stream and everything is working, because if I use smaller files with the same function, it works fine.  The problem only happens when I use a huge file, and it tends to happen late in the process when it's near the end of writing the file.

Advertisement

Firstly, you've been told before not to throw all your questions into For Beginners. I'm moving this to the general programming forum.

Secondly, show code, and explain exactly what this exception is that you see. We're not here to second-guess what you're doing which may or may not be wrong.

 

3 hours ago, Kylotan said:

Firstly, you've been told before not to throw all your questions into For Beginners. I'm moving this to the general programming forum.

 

OK, sorry.  I wasn't sure where it belonged because it seems like a relatively simple problem and people used to keep telling me that the things I post should be moved to beginners.  So for future reference, what kinds of things are intended for the beginners forum?

 

3 hours ago, Kylotan said:

Secondly, show code, and explain exactly what this exception is that you see. We're not here to second-guess what you're doing which may or may not be wrong.

I don't know why everyone ALWAYS expects me to post code.  Yes, I understand that in many cases it can be more convenient, but doesn't anyone else understand the concept of confidentiality?  I narrowed the problem down to a specific line.  I KNOW for certain that nothing else is causing it either directly or indirectly, because as I said, the stream works for all but the largest files.  And all the line does it write data from an already existing array into a file.  So here's the line, or something so similar that you wouldn't be able to tell the difference:

 

fs.WriteByte(bytes);

 

fs is a file stream, bytes is an array of bytes, and i is the index of a for loop.  Happy now?

 

And the exception is called OutOfMemoryException.  I thought that was a common enough one that pretty much anyone would recognize it.

1 minute ago, myvraccount said:

So for future reference, what kinds of things are intended for the beginners forum?

If you visit the For Beginners forum, there is a thread about this.

 

2 minutes ago, myvraccount said:

I don't know why everyone ALWAYS expects me to post code.

Because that's where the errors are.

 

2 minutes ago, myvraccount said:

Happy now?

No. Post a proper question with some decent context or don't waste our time.

This topic is closed to new replies.

Advertisement