locked
Silly marshal question: check copy is valid RRS feed

  • Question

  • So here is a weird question that was posed to me by a co-worker for some interop/unsafe code we have.

    Is there a way to check is the memory block we're trying to copy from/to is valid before doing so with a Marshal.Copy? We are doing pokemon exception handling (gotta-catch-em-all) and exceptions thrown by the Marshal.Copy is a hardware exception so it cannot be caught. I'd think that there would be someway to ask the OS if the block of memory was owned by this software or not, but as we are getting into the realm of unmanaged, it's probably "No, just don't screw up your pointers, you silly programmer".

    • Moved by Lie You Wednesday, March 28, 2012 2:25 AM Move it for better support. (From:Visual C# General)
    Monday, March 26, 2012 6:31 PM

Answers

  • Hi Idea,

    I am not 100% sure but I would think that the exceptions are Corrupted State Exceptions and you can catch these exceptions, too.

    The following article published on MSDN magazien might be worth a look: http://msdn.microsoft.com/en-us/magazine/dd419661.aspx

    With kind regards,

    Konrad

    • Marked as answer by Idea Hat Wednesday, March 28, 2012 1:46 PM
    Wednesday, March 28, 2012 12:31 PM