[ Slice ]
The return value of the
is a simple structure that contains a length and a pointer to an external byte array. Returning a
is a cheaper alternative to returning a
since we do not need to copy potentially large keys and values.
C++ strings and null-terminated C-style strings can be easily converted to a Slice:
A Slice can be easily converted back to a C++ string:
Be careful when using Slices since it is up to the caller to ensure that the external byte array into which the Slice points remains live while the Slice is in use. For example, the following is buggy: