c++ - Windows/Linux下直接访问内存设备

标签 c++ windows linux input

你好
我目前正在编写一个软件来测试闪存设备的完整性。 (使用 C++ iostreams)

为了实现这个目标,随机内容的文件被写入设备,读回,复制,移动,比较(我把设备置于压力条件下,不时检查数据是否有效)...< br/> 表面上一切都很好,但幕后却有问题。

当我分析通过 ATA/SATA 电缆(使用 Bus Doctor)发送到设备的命令时,我发现(尤其是)读取命令通常不会执行。然而,数据对程序可用。所以它们必须来自缓冲区,这对我来说是 Not Acceptable 。每当我读取数据时,它都必须直接来自磁盘,而不是来自缓存。读/写性能根本不重要。

但我还没有找到告诉 Windows 不要缓冲任何东西的方法(在设备管理器中可以选择停用特定设备的写缓存,但没有达到预期的效果)。
如果有人知道怎么做:请告诉我
(关于 Linux 的任何建议也是如此。我想我会在那里遇到同样的问题)

到目前为止,我唯一能想到的解决方案是直接 I/O。
我为 Windows 找到的是这样的:

http://www.internals.com/utilities_main.htm

The WinIo library allows 32-bit Windows applications to directly access I/O ports and physical memory. It bypasses Windows protection mechanisms by using a combination of a kernel-mode device driver and several low-level programming techniques.

http://www.direct-io.com/

Direct I/O is the world's first device driver for Microsoft Windows NT, Windows 2000, Windows XP and Windows Server 2003 which enables the direct hardware access for your existing software without any programming efforts on your side

问题:
有没有人遇到过类似的问题,可以给我一些建议吗?
我真的必须使用 Direct I/O 还是有一些我没有找到的操作系统选项/设置(Windows 或 Linux)
你知道其他用于直接 I/O 的库吗(Windows 或 Linux 或者更好的:两者都有)

最佳答案

对于 Windows,您可以 disable buffering using the Win32 API直接。

When opening or creating a file with the CreateFile function, the FILE_FLAG_NO_BUFFERING flag can be specified to disable system caching of data being read from or written to the file. Although this gives complete and direct control over data I/O buffering, in the case of files and similar devices there are data alignment requirements that must be considered.

不确定这是否可以在 C++ 标准库中完成。您可以在 iostream 级别禁用缓冲,但这可能不会影响 O/S 缓冲。

关于c++ - Windows/Linux下直接访问内存设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4025179/

相关文章:

c++ - 行计数,如何处理CRLF?

c++ - MSVC Address Sanitizer - 有什么理由在发布版本中使用它吗?

c++ - Windows:无法在谷歌上找到 SAPI 错误

linux - DLNA FLAC 音频客户端可以在 Linux 上 headless 地工作吗?

linux - 如何使用命令或脚本在文本文件中放置分隔符

c++ - 如何将 union 发送到函数

c++ - 检测到 mac 文件格式;替代高级保存选项

c++ - 在 Visual Studio 2012 Express 中设置 C++ 调试环境

linux - Lynx 对 Google 搜索的请求不起作用

c++ - 如何将 Boost.uuid 集成到我的跨平台代码中?