Hi,
Can anyone give me a simple example of how to use SafebUffer. i.e how do I create and initialise one - MSDN docs don't appear to show this.
Hi,
Can anyone give me a simple example of how to use SafebUffer. i.e how do I create and initialise one - MSDN docs don't appear to show this.
You can't, it is an abstract class. The only visible concrete implementation of it is SafeMemoryMappedViewHandle, a helper class for the classes in the System.IO.MemoryMappedFiles namespace. It has a non-accessible constructor since it can only be properly initialized by the plumbing that makes memory mapped files work.
The use case is an IntPtr that maps to unmanaged memory, managed by a handle. Fairly rare in the Windows API, MapViewOfFile or GlobalAllocPtr for example. If you want to create your own then you have to derive from SafeBuffer so you can call its constructor and call, say, AcquirePointer. Most of this is unsafe. What are you really trying to do?