3 ms·
Do you have a brief example, or is it the normal "I am a str".to_string()? I still have a long way to go with learning how Rust works. I've heard about zero-co
by nevi-me 8y ago
Do you have a brief example, or is it the normal "I am a str".to_string()? I still have a long way to go with learning how Rust works.
I've heard about zero-copy in C and C++, but don't have an idea of how it's implemented in practise.
- carlmr 8y agoBasically what you can do is, e.g. Reading in a file. Now you have a string containing all your file. When you then write a parser you can write it so that it uses string slices pointing into your file buffer whenever it references any text from your file, instead of creating new strings. As long as you don't need to modify anything you don't need to create any copies and the borrow checking compiler will ensure that you don't invalidate any part of your buffer. For a lot of parsers string allocation is a big part of runtime performance.