如何在 C# 中使用 SafeBuffer
如何使用 SafebUffer 的简单示例是什么?也就是说,我如何创建并初始化一个? MSDN 文档似乎没有显示这一点。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能,它是一个抽象类。它唯一可见的具体实现是 SafeMemoryMappedViewHandle,它是 System.IO.MemoryMappedFiles 命名空间中的类的辅助类。它有一个不可访问的构造函数,因为它只能由使内存映射文件工作的管道正确初始化。
用例是映射到由句柄管理的非托管内存的 IntPtr。例如,在 Windows API、MapViewOfFile 或 GlobalAllocPtr 中相当罕见。如果您想创建自己的,则必须从 SafeBuffer 派生,以便可以调用其构造函数并调用 AcquirePointer。其中大部分都是不安全的。您真正想做什么?
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?