由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - what is the most efficient way to trim a string in C++?
相关主题
有没有办法让一个类的变量只读,不是const?第五版的 c++ primer 出来了
About Longest repeated substringC++ 11 课程 (视频 ):Rvalue Reference
这个有更好的算法吗?C++项目大部分失败了,统计数据在哪里?
java questionlisper
准备面试一个java-based position,有什么书推荐一下?这二个在C++中有区别不?
register variableC++11的这个method有啥用?
C++ vector 一边遍历一边删大家觉得C++复杂在哪里?
post incrementjava多维数组,其实是个很好的商业机会啊
相关话题的讨论汇总
话题: c++话题: string话题: most话题: efficient话题: trim
进入Programming版参与讨论
1 (共1页)
l*********s
发帖数: 5409
1
Since the returned value is a substring of the original input, can it be
done without memory copy operations?
g*****g
发帖数: 34805
2
I doubt that'll be a bottleneck in most systems.

【在 l*********s 的大作中提到】
: Since the returned value is a substring of the original input, can it be
: done without memory copy operations?

l*********s
发帖数: 5409
3
That is why I am only asking the solution in C++ :-)

【在 g*****g 的大作中提到】
: I doubt that'll be a bottleneck in most systems.
t****t
发帖数: 6806
4
if it is a std::string, most likely it is not possible. in c++0x you may
have option to use moving semantics but i don't see obvious benefit here.
if it is a char*, you may do it, however usually it's not a good design.

【在 l*********s 的大作中提到】
: Since the returned value is a substring of the original input, can it be
: done without memory copy operations?

j*a
发帖数: 14423
5
你input的是char *c,指向空间0x1234内容是"blahblah\0"
返回一个char *d,还指向空间0x1234内容改为"ahbl\0"不行吗?
是我没明白你问的?

【在 l*********s 的大作中提到】
: Since the returned value is a substring of the original input, can it be
: done without memory copy operations?

l*********s
发帖数: 5409
6
my input is c++ string, not c char *.

【在 j*a 的大作中提到】
: 你input的是char *c,指向空间0x1234内容是"blahblah\0"
: 返回一个char *d,还指向空间0x1234内容改为"ahbl\0"不行吗?
: 是我没明白你问的?

l*********s
发帖数: 5409
7
Thank you!

【在 t****t 的大作中提到】
: if it is a std::string, most likely it is not possible. in c++0x you may
: have option to use moving semantics but i don't see obvious benefit here.
: if it is a char*, you may do it, however usually it's not a good design.

p***o
发帖数: 1252
8
Many years ago, I saw a piece of code that tries to modify the string
by removing the left-most character, one at a time. That turns an O(n)
algorithm into an O(n^2) one, and of course it becomes the bottleneck ...

【在 g*****g 的大作中提到】
: I doubt that'll be a bottleneck in most systems.
r*****s
发帖数: 51
9
space-time tradeoff

【在 p***o 的大作中提到】
: Many years ago, I saw a piece of code that tries to modify the string
: by removing the left-most character, one at a time. That turns an O(n)
: algorithm into an O(n^2) one, and of course it becomes the bottleneck ...

g*****g
发帖数: 34805
10
Not likely if it's a standard function. My point is 20% of codes are
ran 80% of time, I prefer the readable code => profile => resolve
bottleneck approach. The common mistake is to optimize prematurely.

【在 p***o 的大作中提到】
: Many years ago, I saw a piece of code that tries to modify the string
: by removing the left-most character, one at a time. That turns an O(n)
: algorithm into an O(n^2) one, and of course it becomes the bottleneck ...

1 (共1页)
进入Programming版参与讨论
相关主题
java多维数组,其实是个很好的商业机会啊准备面试一个java-based position,有什么书推荐一下?
数组,结构,类在数值计算中哪个快register variable
新手请教Java数组问题C++ vector 一边遍历一边删
Think Pythonpost increment
有没有办法让一个类的变量只读,不是const?第五版的 c++ primer 出来了
About Longest repeated substringC++ 11 课程 (视频 ):Rvalue Reference
这个有更好的算法吗?C++项目大部分失败了,统计数据在哪里?
java questionlisper
相关话题的讨论汇总
话题: c++话题: string话题: most话题: efficient话题: trim