背景
每一个cpp expression都有一个type 和 value category 属性 前者大家都比较了解,但是后者却常常被忽视
Value Categories in the c language
cpp是由c语言发展而来,因此这里先介绍c 语言中的value category
阅读更多最近在做一个智能算力的项目,其中需要用到redis维护某个全局的时间窗口
资料
复杂数据结构的表示方式
学习过程中唯一让我迷惑的是一个嵌套的数据结构要如何表示 比如我想表示一个key为string, value为List的Hash 按照c++的语法,也就是一个
阅读更多接口
一个ABC,后面会继承这个类做各种实现
clean up function
代码比较好懂,唯一让我感到疑惑的是 clean up function 这部分
1 2 // FIXME: 不太理解为什么需要很多个clean up function 3 // Cleanup functions are stored in a single-linked list. 4 // The list's head node is inlined in the iterator. 5 struct CleanupNode { 6 // True if the node is not used. Only …
阅读更多arena时levelDB中的内存池实现
接口
没有太多好说的,都非常直观。 补了些注释
1 2class Arena { 3 public: 4 Arena(); 5 6 Arena(const Arena&) = delete; 7 Arena& operator=(const Arena&) = delete; 8 9 ~Arena(); 10 11 // Return a pointer to a newly allocated memory block of "bytes" bytes. 12 char* Allocate(size_t bytes); …
阅读更多FilterPolicy接口
1 2class LEVELDB_EXPORT FilterPolicy { 3 public: 4 virtual ~FilterPolicy(); 5 6 // Return the name of this policy. Note that if the filter encoding 7 // changes in an incompatible way, the name returned by this method 8 // must be changed. Otherwise, old incompatible filters may be 9 // …
阅读更多Cache接口
没有太多好说的,可以注意这里用了void*来表示任意类型数据。 在c++17之后可以考虑用std::any代替,参考 std::any 笔记
1 2 3namespace leveldb { 4 5class LEVELDB_EXPORT Cache; 6 7// Create a new cache with a fixed size capacity. This implementation 8// of Cache uses a least-recently-used eviction policy. 9LEVELDB_EXPORT Cache* NewLRUCache(size_t …
阅读更多概述
std::shared_ptr是智能指针的一种,在modern c++中被广泛使用(
甚至滥用)虽然天天使用,但是有些细节还不是100%清楚,因此来整理一下 为了方便表述,下文只写shared_ptr,不在写std的namespace.
阅读更多背景
一种很常见的背景是,需要表示未知类型的数据。 比如可能是用户提供的数据,比如是一个Cache的实现, value想支持任意类型的数据
对于这种场景,c语言的出身的开发者通常会使用void*来实现
阅读更多levelDB是一个有序的KV存储,因此key的顺序是十分关键的 levelDB提供用户自己定义key顺序的能力
先看下comparator的接口
接口 include/leveldb/comparator.h
1 2// A Comparator object provides a total order across slices that are 3// used as keys in an sstable or a database. A Comparator implementation 4// must be thread-safe since leveldb may invoke its methods …
阅读更多