Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage string slices with less overhead?

I'm dealing with giant (up to 2GB) strings and their slices in C++ program. C-style strings seem to be unreliable under such circumstances, but can be sliced trivially (without '\0' at the end). On the other hand, as I understood, std::string::substr copies the slice, therefore I should perform at least one extra addition operation (index + base) per indexing in order to keep memory usage rational.

like image 810
leventov Avatar asked Feb 21 '23 13:02

leventov


1 Answers

The most general solution would be to create a slice object, with the interface you need, and use that. The slice object could consist of two iterators, the start and the end.

like image 149
James Kanze Avatar answered Mar 08 '23 15:03

James Kanze