如何使用SGI STL hash_map?
我正在尝试使用从他们的网站下载的 SGI STL 实现。 我想使用哈希图,因为我必须存储大约 5.000.000 条记录,但它应该很好:我需要能够非常快速地访问它。 我尝试过 stedext::hash_map
,但速度非常慢,因为我无法设置初始大小。 顺便问一下,可以这样做吗? 如果我将附加路径添加到 MS Visual Studio,我什至无法从 SGI 站点编译示例。 我收到一条错误消息:
error C2061: syntax error : identifier 'T'.
还有其他人遇到过此类问题吗?
I am trying to use the SGI STL implementation I have downloaded from their site. I want to use a hashmap, because I have to store around 5.000.000 records, but it should be good: I need to be able to access it very quickly. I've tried stedext::hash_map
, but it was very slow because I couldn't set the initial size. By the way, is it possible to do that?
If I add the additional path to my MS Visual Studio, I can't even compile the example from the SGI site. I get an error message:
error C2061: syntax error : identifier 'T'.
Has anyone else faced such problems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我承认我还没有亲自尝试过,但 VS2008 应该支持 TR1,其中包含:
它位于“功能包”版本中。
http://www.microsoft.com/downloads/details.aspx microsoft.com/downloads/details.aspx?FamilyId=D466226B-8DAB-445F-A7B4-448B326C48E7&displaylang=en
I confess I haven't tried it for myself, but VS2008 is supposed to support TR1 which contains:
it's in a "feature Pack" release.
http://www.microsoft.com/downloads/details.aspx?FamilyId=D466226B-8DAB-445F-A7B4-448B326C48E7&displaylang=en
我已经使用它很多次了,没有出现任何问题,尽管我将它与 gcc(在 Windows 和 Linux 上)而不是 Visual Studio 一起使用。
对于实际使用,文档位于此处。
您可以使用指定要保留的存储桶数量。
关于您的标识符 T 问题,我假设您忘记将名为 T 的模板参数替换为实际类型。 如果您无法弄清楚,也许可以粘贴一段有关如何使用 hash_map 的代码片段。
文档中的示例:
当然,如果您愿意,您可以使用 std::string 而不是 char* :
I have used it a number of times without problems, though I used it with gcc (both on windows and linux) and not Visual Studio.
For actual usage, the documentation is here.
You can specify how many buckets to reserve using
Regarding your issue with identifier T, I assume you have forgotten to replace a template argument, named T, with an actual type. If you can't figure it out, maybe paste a code snippet of how you are using the hash_map.
Example from the documentation:
Of course, you can use std::string instead of char* if you wish:
当您尝试构建/编译项目时是否出现任何其他错误消息?
你提到你...
你能扩展一下吗? 您可以在 Visual Studio 项目设置中的许多位置添加目录。 即添加额外的包含头路径、额外的库路径等。您在哪里添加目录?
Are there any other error messages showing up when you try to build/compile your project?
You mentioned you...
Could you expand on that a bit? There are many places you can add directories in visual studio project settings. i.e. adding additional include header paths, additional library paths, etc. Where did you add your directory?
听起来很有道理。 你的STL目录的结构是什么? 您是从他们的网站获得所有 SGI STL 文件还是仅获得一个? 可能是您缺少依赖文件,从而导致您看到错误。
That sounds reasonable. What is the structure of your STL directory? Did you get all the SGI STL files from their website or just a single one? It could be that you're missing a dependency file which is resulting in the error you are seeing.
我已经下载了这个库的压缩版本,该压缩文件中只有头文件。 Linker下还有一个选项,叫做附加依赖项,但那里只有*.lib文件。
我的设置的命令行看起来:
我不知道它是否更有用......
I've dowloaded the zipped version of this library, there are only header files in that zip. There is another option under Linker, it is calles additional dependencies, but there are only *.lib files there.
The command line of my settings looks:
I don't whether it is more usable....
是的,您只能找到 SGI STL 网站上标明的头文件。 正如您所注意到的,链接依赖项仅适用于 .lib 文件,因此不必费心在其中添加任何内容。
您还在编译 Dan 发布的示例吗? 您可能需要使用引号而不是方括号来指定包含标头。 因此,使用...
而不是...
这可能是编译器如何搜索包含文件的问题。 作为附加询问,您使用的是哪个版本的 Visual Studio?
Yes you will only find header files, that is indicated on the SGI STL website. As you noticed the link dependencies are for .lib files only so don't bother adding anything there.
You are compiling the example posted by Dan still right? You may need to specify your include headers using quotes rather than brackets. So use...
instead of...
It could be an issue with how include files are being searched for by the compiler. As an additional inquiry what version of Visual Studio are you using?
正如我在一个讨论论坛上注意到的关于这个问题的主题中指出的那样,SGI STL 实现似乎已经很长时间没有更新了。 在下载页面上,它甚至提到最后一次更新时间是 2000 年 6 月 8 日。 我怀疑让 SGI STL 实现在 VS 2005/2008 下工作比它的价值更麻烦。
我建议检查一些 STL 替代品...
两者都会定期更新。
As was pointed out in a thread I noticed on a discussion forum about this issue the SGI STL implementation doesn't seem to have been updated in a very long time. On the download page it even mentions 8 Jun 2000 as the last time it was updated. I would suspect getting the SGI STL implementation to work under VS 2005/2008 is more trouble than its worth.
I would suggest checking out some STL alternatives...
Both are updated regularly.