I am writing a managed wrapper for a game engine written in C to challenge myself. I have started to wrap unmanaged pointers in SafeHandle
derivatives, but it donned on me that calls to the unmanaged functions that could return the same pointer will probably create new SafeHandles, and if one of them gets disposed, the rest of them will become invalid.
How can I prevent this from happening efficiently? I doubt the marshaller automagically tracks duplicates...