[plt-scheme] sizeof

From: Synx (plt at synx.us.to)
Date: Tue Jan 5 17:39:15 EST 2010

Dave Gurnell wrote:
> Hi all,
> Is there a simple way of estimating the number of bytes of RAM that a particular piece of data is occupying?
> e.g.
>     (sizeof some-large-data-structure) ; ==> 1024 bytes

That would be simple, until you consider the case of some joker making a
piece of data as (list (current-custodian)). What's the size of that?
Your entire memory! The problem is that structured data doesn't actually
contain the data, only a pointer to that data. Determining the size of
the pointers isn't often useful, but determining the size of the data
risks that your data structures end up encompassing the entire computer,
since though a structure can't easily hold everything, it can easily
point to everything.

(sizeof (make-thingy (current-custodian) (current-continuation-marks)
(current-eventspace)) => ?

It would be much better for you to just measure the memory before and
afterwards, to tell how much memory a certain /operation/ is consuming
or reserving. The data structures themselves don't take an easily
definiable amount of memory separable from the operation that creates
them. So, according to the attached program, each "thingy" struct takes
about 430 bytes of memory. Wait what
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: memory-use-thingy.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20100105/19174647/attachment.ksh>

Posted on the users mailing list.