开发者

How to use a SafeBuffer in C#

开发者_开发问答

What is a simple example of how to use SafebUffer? That is, how do I create and initialise one? MSDN documentation 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜