Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find size of single object in memory

Tags:

julia

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?

like image 682
Michael Ohlrogge Avatar asked Jan 31 '16 19:01

Michael Ohlrogge


People also ask

How do you find the size of an object?

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.

How do you find the size of an object in a byte?

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.

How do you check the memory size of an object in Python?

In Python, the most basic function for measuring the size of an object in memory is sys. getsizeof() .

How do I get the size of an object in C#?

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).


1 Answers

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.

like image 190
amrods Avatar answered Oct 24 '22 15:10

amrods