Memory size of an arbitrary collection?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Memory size of an arbitrary collection?

Steve Cline
Is there a method (or sample code) that I can send to a heterogeneous collection of objects to find out how much space it takes up? Something like:

#( 1 $a 'abc'  #('def' 'hijk') ) memorySize

which would yield the number of bytes occupied by the collection.
Reply | Threaded
Open this post in threaded view
|

Re: Memory size of an arbitrary collection?

Steve Cline
and the answer is:

SystemAnalyzer new byteSizeOfObject: #( 1 $a 'abc'  #('def' 'hijk') )
Reply | Threaded
Open this post in threaded view
|

Re: Memory size of an arbitrary collection?

Terry Raymond
Steve

Not really, try SystemAnalyzer new byteSizeOfObject: (Array new: 4).

You should look at ObjectMemory>>numOopsNumBytesIn:

In your example,  you will need to recursively compute the bytes used by
each object.

If the objects can recursively refer to each other, then you should put each
object into dictionary, like you would with a dictionary based deep copy,
and then compute the size of each object in the dictionary.

Terry

===========================================================
Terry Raymond
Crafted Smalltalk
80 Lazywood Ln.
Tiverton, RI  02878
(401) 624-4517      [hidden email]
===========================================================

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Steve Cline
> Sent: Monday, May 21, 2012 1:04 PM
> To: [hidden email]
> Subject: Re: [vwnc] Memory size of an arbitrary collection?
>
> and the answer is:
>
> SystemAnalyzer new byteSizeOfObject: #( 1 $a 'abc'  #('def' 'hijk') )
>
> --
> View this message in context: http://forum.world.st/Memory-size-of-an-
> arbitrary-collection-tp4631202p4631215.html
> Sent from the VisualWorks mailing list archive at Nabble.com.
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Memory size of an arbitrary collection?

Steve Cline
Terry, thanks for the other method.

Some sample code with suprising results (to me at least):

| p1 p2 |
p1 := SwcPerson new firstName: 'abcdefhijklmnopqrstu' ; lastName:  'bcdefhijklmnopqrstuv' ; yourself.
p2 := SwcPerson new firstName: 'cdefhijklmnopqrstuvw' ; lastName:  'defhijklmnopqrstuvwx' ; yourself.

(SystemAnalyzer new byteSizeOfObject: p1) inspect.
(SystemAnalyzer new byteSizeOfObject: p2) inspect.

(ObjectMemory current numOopsNumBytesIn: ( Array with: p1 with: p2) ) inspect.

The inspectors show 20, 20, & #( 2 40 ) . I would have expected the answers to be "over 40" (two 20 character strings plus some overhead for the instance structure), "over 40", and #(2 "over 80").

What am I missing?
Reply | Threaded
Open this post in threaded view
|

Re: Memory size of an arbitrary collection?

Mark Plas
Hi Steve,

The methods you're using to calculate the size of an object don't take the entire object graph into account. They just measure the size of the object that's given as an argument, and don't measure all other objects that are referenced by it through its instance variables.

There is however a package in the public repository, called "TAG-MemoryUsage", that allows you to do what you're after.

Mark

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Steve Cline
Sent: dinsdag 22 mei 2012 16:31
To: [hidden email]
Subject: Re: [vwnc] Memory size of an arbitrary collection?

Terry, thanks for the other method.

Some sample code with suprising results (to me at least):

| p1 p2 |
p1 := SwcPerson new firstName: 'abcdefhijklmnopqrstu' ; lastName:
'bcdefhijklmnopqrstuv' ; yourself.
p2 := SwcPerson new firstName: 'cdefhijklmnopqrstuvw' ; lastName:
'defhijklmnopqrstuvwx' ; yourself.

(SystemAnalyzer new byteSizeOfObject: p1) inspect.
(SystemAnalyzer new byteSizeOfObject: p2) inspect.

(ObjectMemory current numOopsNumBytesIn: ( Array with: p1 with: p2) ) inspect.

The inspectors show 20, 20, & #( 2 40 ) . I would have expected the answers to be "over 40" (two 20 character strings plus some overhead for the instance structure), "over 40", and #(2 "over 80").

What am I missing?

--
View this message in context: http://forum.world.st/Memory-size-of-an-arbitrary-collection-tp4631202p4631396.html
Sent from the VisualWorks mailing list archive at Nabble.com.
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Memory size of an arbitrary collection?

Steve Cline
I tried the TAG-MemoryUsage package and it shows the SwcPerson instances as having 84 bytes in 3 objects, and the array as having 188 bytes in 7 objects, much more along the lines of what I might expect - thanks!