I know that the varinfo()
function will give the size of all objects in memory. This can be quite slow to execute, and will at times fail on certain objects, making the whole function hang. Is there a way to get the size in memory of a specific object, similar to the sys.getsizeof()
function in Python?
One way to get an estimate of an object's size in Java is to use getObjectSize(Object) method of the Instrumentation interface introduced in Java 5. As we could see in Javadoc documentation, the method provides “implementation-specific approximation” of the specified object's size.
getsizeof() can be done to find the storage size of a particular object that occupies some space in the memory. This function returns the size of the object in bytes.
In Python, the most basic function for measuring the size of an object in memory is sys. getsizeof() .
C# has a 'sizeof' operator that works like it does in C++, however it returns the size that a field of that type will be. Thus for reference types (class, not struct), it will always return the size of a pointer (4 on 32 bit systems).
varinfo()
accepts regular expressions to match object names, so you can use something like
x = rand(100, 100)
varinfo(r"x")
to get info on x
. For the size in bytes use
Base.summarysize(x)
EDIT:
Originally this answer recommended whos()
, however as @Plankalkül mentions whos()
has been renamed to varinfo()
, the answer was updated accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With