Leveldb Advanced - Tekkaman

Datetime:2016-08-23 00:48:19          Topic: Leveldb           Share

[ Slice ]

The return value of the  it->key()  and  it->value()  is a simple structure that contains a length and a pointer to an external byte array. Returning a  Slice  is a cheaper alternative to returning a  std::string  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:





About List