作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在编写一个对延迟敏感的应用程序,它在初始化时读取文本文件。我分析并重写了我所有的算法,这样我 85% 的执行时间来自以下几行:
boost::interprocess::file_mapping file(Path, read_only);
boost::interprocess::mapped_region data(file, read_only);
我在 Windows 上写这篇文章 - 有没有更快的方法将文件映射到内存中?便携性不是问题。
最佳答案
您可以只使用 Win32 的 native 函数,但我认为您不会节省很多,因为 boost 不会增加很多开销:
OFSTRUCT ofStruct;
ofStruct.cBytes=sizeof (OFSTRUCT);
HANDLE file=(HANDLE)OpenFile(fileName, &ofStruct, OF_READ);
if (file==INVALID_HANDLE_VALUE)
handle errors
else {
HANDLE map=CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, 0);
if (map==INVALID_HANDLE_VALUE)
handle errors
else {
const char *p=(const char *)MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0));
if (p) {
// enjoy using p to read access file contents.
}
// close all that handles now...
}
关于c++ - 比 boost::file_mapping 更快的读取文件的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13905789/
我正在创建一个基于文件的点云八叉树,以便在非常大的文件(无法存储在 ram 中)上管理过滤器。这个方法的瓶颈,到目前为止,是叶子的I/O(因为我经常要写,重写文件和读取文件......) 所以我想使用
我有一个文件解析器,它将文件加载为文件映射对象,然后根据调用者的需求映射区域。可以在本地或通过网络访问这些文件。 这个文件读取是顺序的。 我有两种方法 - Approach 1 Create a fi
我正在编写一个对延迟敏感的应用程序,它在初始化时读取文本文件。我分析并重写了我所有的算法,这样我 85% 的执行时间来自以下几行: boost::interprocess::file_mapping
对于这个问题,我将一个大的三维体从文件加载到一个程序中,但通常一次只需要查看三个平面 (x,y,z)。我目前正在使用 Boost::Interprocess::File_Mapping 创建文件 (3
我是一名优秀的程序员,十分优秀!