Reputation: 89
The integer (long) type definition effectively looks like this (once the C macros are expanded):
struct _longobject {
long ob_refcnt;
PyTypeObject *ob_type;
size_t ob_size;
uint32_t ob_digit[1];
};
Here, what does ob_size mean and what its value represents?
Upvotes: 2
Views: 526
Reputation: 77367
Python _longobject
(A.K.A. int
) is variable size and that is the standard python header for variable objects. From 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
is allocated on the heap in a memory block large enough to hold long ob_digit[ob_size]
long integers.
Upvotes: 2