请求快速处理'char'字符串的帮助 [英] Requesting help on fast handling of string of 'char'

查看:126
本文介绍了请求快速处理'char'字符串的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我正在执行一项性能至关重要的项目,该项目需要大量的char字符串处理和char字符串操作.

std::string用于上述目的会减慢应用程序的速度,而我迫切需要更快的东西.

处理char字符串的最快方法是什么?
任何帮助将不胜感激.

预先感谢.

Hello Everybody.

I am working on a performance critical project which requires a lot of char string handling and char string manipulation.

Using the std::string for the mentioned purposes, is slowing down the application and I am in desperate need of something faster.

What would be the fastest approach to handle the char strings?
Any help would be highly appreciated.

Thanks in advance.

推荐答案

好,您需要定义字符串处理"和字符串处理"的含义.通过操纵,您是在谈论字符串复制,串联还是什么?

如果您需要字符串连接,请查找此SO讨论 [ ^ ],有关字符串搜索,请参见快速字符串搜索" [
Well you need to define what you mean by "string handling" and "string manipulation". By manipulation are you talking about string copying, concatenation or what?

If you have a need for string concatenation, look for this SO discussion[^], for string searching, see ''fast string search''[^]. By no means this is the end game, there is a whole lot more, but it will be decent starting point.


如果您要进行文本处理/解析-您可以考虑使用
GNU野牛 [ ^ ]

flex [ ^ ]

请记住,您可以单独使用flex,而且速度相当快:)

除此之外,我认为您会发现使用指针没有什么用,使用带有页面大小的块或内存映射的IO的ReadFile读取文件可能无济于事.

如果要继续使用std :: string;记住要通过引用传递,并记住您可以使用const char* string.c_str() const函数访问字符串内容.

问候
Espen Harlinn
If you are doing text processing/parsing - you could consider using
GNU Bison[^]
and
flex[^]

Remeber that you can use flex on its own, and it is reasonably fast :)

Apart from that, I think you will find that nothing beats using pointers, and possibly reading files using ReadFile with OS page sized chunks or memory mapped IO.

If you want to continue using std::string; remember to pass by reference, and remember that you have access to the string contents using the const char* string.c_str() const function.

Regards
Espen Harlinn


这取决于您最常对字符串执行哪些操作.

一个问题可能是std :: string的实现方式:只需尝试另一种STL实现,例如 stlport [ std :: rope [此处 [
It depends on which operations you do most often on the string.

One problem can be the way std::string is implemented: just try another STL implementation, like stlport[^]
They use reference counted string, thus removing lot of buffer copy.

Another can be the fact you do frequent insertion and deletion in the middle of the strings.
If so, string (that is: a buffer of memory-consecutive characters) is not as efficient.
Try std::rope [^]instead .

A discussion about the difference can be found here[^]


这篇关于请求快速处理'char'字符串的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆