integer (long)类型定义实际上如下所示(展开C宏后):
struct _longobject {
long ob_refcnt;
PyTypeObject *ob_type;
size_t ob_size;
uint32_t ob_digit[1];
};这里,ob_size是什么意思,它的值代表了什么?
发布于 2020-12-15 04:43:20
Python _longobject (又称int)是可变大小的,它是可变对象的标准python头文件。来自object.h
/* PyObject_VAR_HEAD defines the initial segment of all variable-size
* container objects. These end with a declaration of an array with 1
* element, but enough space is malloc'ed so that the array actually
* has room for ob_size elements. Note that ob_size is an element count,
* not necessarily a byte count.
*/_longobject在堆上分配的内存块足够大,可以容纳long ob_digit[ob_size]长整数。
https://stackoverflow.com/questions/65295570
复制相似问题