Find the size of one object in memory

I know that the whos() function will give the size of all objects in memory. This can be quite slow to execute, and sometimes interrupts on certain objects, causing the entire function to hang. Is there a way to get the size in memory of a specific object, similar to the sys.getsizeof() function in Python?

+7
julia-lang
source share
2 answers

whos() accepts regular expressions to match object names, so you can use something like

 x = rand(100, 100) whos(r"x") 

to get information about x . For size in bytes use

 Base.summarysize(x) 
+12
source share

You can use the sizeof function:

 help?> sizeof search: sizeof sizeof(s::AbstractString) The number of bytes in string s. sizeof(T) Size, in bytes, of the canonical binary representation of the given DataType T, if any. julia> x = rand(100, 100); julia> sizeof(x) 80000 
+4
source share

All Articles