0

While I am still new to C# I'm curious if there is a way to tell windows that it needs to set aside X memory to run this application.

While debugging (F5) I occasionally get a random "error writing to protected memory" notice, and it's usually fine for a bit after I restart the version of Visual Studio. Once in a while it takes a windows Reboot. So I'm assuming I need to specify somewhere a larger memory size for windows to set aside and then collect later.

Thoughts?

2
  • 2
    If you were running out of memory, you'd get an OutOfMemory exception. The error more often means you have unsafe or C++ code that is accessing memory addresses you don't have access to, such as reading/writing too far given an image's buffer pointer. Commented Aug 12, 2009 at 19:08
  • I'm actually just playing with converting an image to a byte[] then sticking it in an IntPtr, and then reversing it. haven't made any dll calls at all. It only happened once today, in the Program.cs, Application.Run line. Said error trying to write to protected memory. Interesting. Commented Aug 13, 2009 at 19:12

2 Answers 2

3

That's not a matter of specifying more memory. That sounds like either you've hit some corner case in the CLR, or you're using some unmanaged code which is misbehaving, or you've got some bad memory.

Do you ever see this problem when not debugging? Is it usually around the same area of code?

Sign up to request clarification or add additional context in comments.

Comments

2

There isn't anything you need to set in Visual Studio or your C# program to prevent this from occurring. It sounds like a more serious problem than that.

You might want to ask this question over at SuperUser.com and see if they have any ideas about the health of your machine and software.

As a person new to c#, you're not really using the unsafe keyword, are you? :)

The beta password for SuperUser can be found here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.