每当我需要存储与特定类型的值(键值 - 例如字符串或其他对象)相关联的一些数据时,我通常使用C++ stdlib映射.stdlib映射实现基于树,它提供比标准数组或stdlib向量更好的性能(O(log n)).
我的问题是,你知道任何C++"标准"哈希表实现提供更好的性能(O(1))吗?类似于Java API中Hashtable类中可用的内容.
在开发C++应用程序时,我不得不使用第三方库,它产生了大量与正在使用的无害#pragma指令相关的警告.
../File.hpp:1: warning: ignoring #pragma ident
In file included from ../File2.hpp:47,
from ../File3.hpp:57,
from File4.h:49,
Run Code Online (Sandbox Code Playgroud)
使用GNU C++编译器时是否可以禁用此类警告?
为了提高从文件读取的性能,我试图将大(几MB)文件的整个内容读入内存,然后使用istringstream来访问信息.
我的问题是,哪个是读取此信息并将其"导入"到字符串流中的最佳方法?这种方法的一个问题(参见下文)是在创建字符串流时,缓冲区被复制,内存使用量增加一倍.
#include <fstream>
#include <sstream>
using namespace std;
int main() {
ifstream is;
is.open (sFilename.c_str(), ios::binary );
// get length of file:
is.seekg (0, std::ios::end);
long length = is.tellg();
is.seekg (0, std::ios::beg);
// allocate memory:
char *buffer = new char [length];
// read data as a block:
is.read (buffer,length);
// create string stream of memory contents
// NOTE: this ends up copying the buffer!!!
istringstream iss( string( buffer ) );
// delete temporary buffer
delete [] buffer;
// close …Run Code Online (Sandbox Code Playgroud) 我是一名C/C++开发人员,这里有几个问题总让我感到困惑.
谢谢
c++ ×4
optimization ×2
hashtable ×1
map ×1
memory ×1
performance ×1
pragma ×1
stream ×1
stringstream ×1
tradeoff ×1
warnings ×1