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 ...
|