Size of an object in memory?
Michael Hudson
mwh at python.net
Wed Nov 14 07:39:20 EST 2001
Fernando Pérez <fperez528 at yahoo.com> writes:
> Is there any way (at runtime, dynamically) to obtain the size in
> bytes of a given object in memory?
Didn't we do this a few days ago? See this thread:
http://groups.google.com/groups?hl=en&threadm=_6FG7.33159%24i4.5175661%40news0.telusplanet.net&rnum=1
but, in short, no, and you don't really want to know.
> Since multiple names may be bound to the same object, is it possible
> to obtain the size of the underlying object and a list of all other
> names bound to it?
Not easily. Or maybe not at all. Oh, hang on: see gc.get_referents.
This may be new in Python 2.2, though.
> I'm writing a runtime object inspector, using the very nice inspect
> module, but inspect doesn't seem to provide this kind of
> information.
It's not obvious (to me) that the information returned by
gc.get_referents will be useful, but it may be. Maybe it should be
used in inspect?
Cheers,
M.
--
First time I've gotten a programming job that required a drug
test. I was worried they were going to say "you don't have
enough LSD in your system to do Unix programming". -- Paul Tomblin
-- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html
More information about the Python-list
mailing list