Create a managed array from a pointer?
-
Is there a way to create a managed array from a pointer to a block of unmanaged memory? I need to allocate a bunch of memory outside of the garbage collector, but I also need to access it through a managed byte array. Is this even possible? Right now, I'm creating the managed array and using a pointer to the first element, but this has a random habit of breaking when the garbage collector decides to move the managed memory around :~. Updating the pointer to the new location isn't really an option, as the pointer is being passed to an unmanaged DLL (which blows up when the GC moves the memory X|). Josh Find a penny, pick it up, and all day long you'll have a back-ache...
-
Is there a way to create a managed array from a pointer to a block of unmanaged memory? I need to allocate a bunch of memory outside of the garbage collector, but I also need to access it through a managed byte array. Is this even possible? Right now, I'm creating the managed array and using a pointer to the first element, but this has a random habit of breaking when the garbage collector decides to move the managed memory around :~. Updating the pointer to the new location isn't really an option, as the pointer is being passed to an unmanaged DLL (which blows up when the GC moves the memory X|). Josh Find a penny, pick it up, and all day long you'll have a back-ache...
-
Thanks for the links. I'd already read the article on pointers, but missed the article on arrays. Unfortunately, I didn't see anything in the array article that would help me create a managed array reference to an unmanaged memory block. I'll just have to think harder, I guess. Josh Find a penny, pick it up, and all day long you'll have a back-ache...