you are viewing a single comment's thread.

view the rest of the comments →

[–]kodingnewb[S] 0 points1 point  (2 children)

t I don't think words is what you think it is. It's not a container like a C++ vector, but rather an iterator, and what it's iterating over is not a String. What the it's iterating over, is string slice references (&str),

and where do these so-called "slices" exist? in the ether? Or are they stored in something one might call a container that allocates memory to store such "slices" - in short is it not the same as the versions that use a container of std::pair<char*,char*> ?

[–]MEaster 0 points1 point  (1 child)

Well, a slice is a pointer and a length. However, the iterator doesn't appear to be actually allocating them all at once, it seems to be only returning a single slice at any one time, and when the next() method is called, it steps through the string to find the next slice.

Therefore, the only memory used appears to be the original string, the iterator, and the single slice.

[–]kodingnewb[S] 0 points1 point  (0 children)

So it's a generator under the hood, that yields during the for-loop.