Reputation: 10990
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?
Upvotes: 22
Views: 12517
Reputation: 2131
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.
Upvotes: 38
Reputation: 7893
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
Upvotes: 9