Jun

Results 58 issues of Jun

## arena 内存池 (arena的管理) 我们来看看arena是如何被管理的。 ```c /*========================================================================== Arena management. `arenas` is a vector of arena_objects. It contains maxarenas entries, some of which may not be currently used (== they're arena_objects...

Python
CPython

```python print('Hello, World') def hello(): print('world') ``` ```python >>> co = compile(open('hello.py').read(), 'hello.py', 'exec') >>> co >>> type(co) ``` Python代码在Python解释器中是以`code`对象存在的。 ``就是`PyCodeObject`对象,定义在`Include/code.h`: ```c /* Bytecode object */ typedef struct { PyObject_HEAD...

Python
CPython

> python中一切都是“对象” # 0x00 PyObject `PyObject`定义在`Include/object.h`,我们来看看这个对象。 ```c typedef struct _object { _PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt; struct _typeobject *ob_type; } PyObject; ``` PyObject中有两个成员的结构体, - `ob_refcnt`,引用记数 - `ob_type`,类型对象的指针 其类型分别为`Py_ssize_t`和`struct _typeobject` ## Py_ssize_t 从名字可以看得出来,`ob_refcnt`就是Python的内存管理机制中基于引用计数的垃圾回收机制的对象引用数。...

Python
CPython

# 0x00 引用计数 > 在Python中,大多数对象的生命周期都是通过对象的引用计数来管理的。 ## 增引用操作 ```c #define Py_INCREF(op) ( \ _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \ ((PyObject *)(op))->ob_refcnt++) ``` ## 减引用操作 ```c #define Py_DECREF(op) \ do { \ PyObject *_py_decref_tmp =...

Python
CPython

Python3中的整数对象`PyLongObject`定义在`Include/longobject.h`: ```c /* Long (arbitrary precision) integer object interface */ typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */ ``` `_longobject`具体实现在`Include/longintrepr.h`: ```c struct _longobject { PyObject_VAR_HEAD digit ob_digit[1]; }; ```...

Python
CPython

Redis 的字典(dict)使用哈希表(hashtable)作为底层实现: ```c // 5.0.3/src/dict.h /* This is our hash table structure. Every dictionary has two of this as we * implement incremental rehashing, for the old to the new...

Redis
Database

> Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX. It's a pre-fork worker model. The Gunicorn server is broadly compatible with various web frameworks, simply implemented, light...

Python

跳跃列表(skiplist)是一种有序数据结构。 Redis 中跳跃列表的结构体表示: ```c // 5.0.3/src/server.h typedef struct zskiplist { // 头节点指针、尾节点指针 struct zskiplistNode *header, *tail; // 节点数量 unsigned long length; // 节点最大层数 int level; } zskiplist; ``` 节点数量 length...

Redis
Database

Redis 中使用 quicklist 作为列表的底层实现之一,quicklist 是 Redis 3.2 版本引入的,在 Redis 3.2 之前,列表的底层实现有 ziplist 和 adlist (A generic doubly linked list) 两种。 ```c // 3.2/src/adlist.h - A generic doubly linked list implementation...

Redis
Database
WIP

进程调度通过在进程之间共享 CPU 时间,达到并行执行的错觉。 下面是 task_struct 结构中和调度相关的几个成员。 ```c // tags/v4.18 - include/linux/sched.h struct task_struct { ... int prio int static_prio; int normal_prio; unsigned int rt_priority; const struct sched_class *sched_class; struct sched_entity...

Linux
WIP