Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the leveldb DB::Get API use std::string as value type?

Tags:

binary

leveldb

I wanna to store key(url) & value(jpg image) in leveldb. As it is said,

Keys and values are arbitrary byte arrays.

how can I use the DB::Get API?

like image 621
caron Avatar asked Dec 08 '25 21:12

caron


1 Answers

Slice does not own the memory (just points to it), so returning a Slice would mean that the caller should free the memory.

So a type with value semantics is needed.

The natural value for binary array would be std::vector<uint8_t>, as it implies so. But std::string can also be used instead (as you pointed out in your answer), and it is more useful if you expect to read a real string (no casting needed).

The main problem is that the reason is not documented, though.

like image 53
user3528030 Avatar answered Dec 12 '25 03:12

user3528030



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!