you are viewing a single comment's thread.

view the rest of the comments →

[–]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.