mirror of
https://github.com/python/cpython.git
synced 2025-09-19 23:20:25 +00:00
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
This commit is contained in:
parent
6495c8da8f
commit
51df064767
9 changed files with 271 additions and 2 deletions
|
@ -3917,6 +3917,17 @@ string_splitlines(PyBytesObject *self, PyObject *args)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(sizeof__doc__,
|
||||
"S.__sizeof__() -> size of S in bytes");
|
||||
|
||||
static PyObject *
|
||||
string_sizeof(PyBytesObject *v)
|
||||
{
|
||||
Py_ssize_t res;
|
||||
res = sizeof(PyBytesObject) + v->ob_size * v->ob_type->tp_itemsize;
|
||||
return PyInt_FromSsize_t(res);
|
||||
}
|
||||
|
||||
#undef SPLIT_APPEND
|
||||
#undef SPLIT_ADD
|
||||
#undef MAX_PREALLOC
|
||||
|
@ -4024,6 +4035,8 @@ string_methods[] = {
|
|||
expandtabs__doc__},
|
||||
{"splitlines", (PyCFunction)string_splitlines, METH_VARARGS,
|
||||
splitlines__doc__},
|
||||
{"__sizeof__", (PyCFunction)string_sizeof, METH_NOARGS,
|
||||
sizeof__doc__},
|
||||
{"__getnewargs__", (PyCFunction)string_getnewargs, METH_NOARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue