0% found this document useful (0 votes)
25 views1 page

What Is The Python Object Overhead For Boolean

The Python object overhead for a boolean is approximately 28 bytes due to the internal structure of Python objects, which includes a reference count, a pointer to the type object, and additional integer internals. Although a boolean theoretically requires only 1 bit, the overhead is necessary for Python's dynamic and object-oriented features. True and False are singletons, meaning only two boolean objects exist in memory, with all other references pointing to these objects.

Uploaded by

Vijay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

What Is The Python Object Overhead For Boolean

The Python object overhead for a boolean is approximately 28 bytes due to the internal structure of Python objects, which includes a reference count, a pointer to the type object, and additional integer internals. Although a boolean theoretically requires only 1 bit, the overhead is necessary for Python's dynamic and object-oriented features. True and False are singletons, meaning only two boolean objects exist in memory, with all other references pointing to these objects.

Uploaded by

Vijay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

what is the python object overhead for boolean

The Python object overhead for a boolean in the standard CPython implementation is primarily
due to the full Python object system structure. A bool object is a subclass of int and shares the
same internal representation, which includes:
A reference count (usually 8 bytes on a 64-bit system),
A pointer to the type object (usually 8 bytes),
Additional integer object internals.
This results in each boolean object consuming about 28 bytes of memory in total, combining the
Python object overhead plus the integer storage internals.
Key points:
The theoretical size of a bool value is just 1 bit, but Python objects carry metadata and
bookkeeping information that requires much more memory.
This overhead (~28 bytes) covers the object header and representation, not just the data.
True and False are singletons, so only two such objects exist; other references point to these
objects.
This design choice prioritizes Python’s dynamic and object-oriented features over memory
minimalism.
This has been confirmed from multiple sources such as Stack Overflow and detailed discussions
about CPython object memory layout [1] [2] [3] .
In summary:
The Python boolean object overhead is about 28 bytes due to Python's object model, including
reference count, type pointer, and integer data structures that represent the bool subtype of int.
References:
Stack Overflow: Python booleans take 24-28 bytes due to object overhead [1] [2]
cs.stackexchange.com explanation on bool size and Python object internals [3]

1. https://stackoverflow.com/questions/34502755/why-do-python-booleans-take-up-more-than-a-byte
2. https://www.reddit.com/r/Python/comments/8pguq5/why_is_a_boolean_variable_24_bytes_in_python/
3. https://cs.stackexchange.com/questions/162451/why-boolean-value-in-python-is-24-28-bytes

You might also like