How to manage string slices with less overhead?

c++, cstring, slice, stdstring, substring

Solution

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.

Problem

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.

Original source