小编Mar*_*nto的帖子

H ++中的Hashtable?

每当我需要存储与特定类型的值(键值 - 例如字符串或其他对象)相关联的一些数据时,我通常使用C++ stdlib映射.stdlib映射实现基于树,它提供比标准数组或stdlib向量更好的性能(O(log n)).

我的问题是,你知道任何C++"标准"哈希表实现提供更好的性能(O(1))吗?类似于Java API中Hashtable类中可用的内容.

c++ performance complexity-theory hashtable map

55
推荐指数
2
解决办法
5万
查看次数

如何禁用#pragma警告?

在开发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++编译器时是否可以禁用此类警告?

c++ compiler-construction warnings pragma

47
推荐指数
5
解决办法
7万
查看次数

如何将文件内容读入istringstream?

为了提高从文件读取的性能,我试图将大(几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++ memory optimization stream stringstream

37
推荐指数
2
解决办法
9万
查看次数

我为什么要使用内联代码?

我是一名C/C++开发人员,这里有几个问题总让我感到困惑.

  • "常规"代码和内联代码之间有很大区别吗?
  • 哪个是主要区别?
  • 内联代码只是宏的"形式"吗?
  • 在选择内联代码时必须做出哪些权衡?

谢谢

c++ optimization tradeoff inline-functions

31
推荐指数
4
解决办法
2万
查看次数