[plt-scheme] sizeof

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Tue Jan 5 11:41:57 EST 2010

My impression is that cons pairs are 3 words, structs are n+2 words
for n fields, strings are n+1 words for n characters, bytes are n/4 +
1 words for a bytes-length of n, vectors are n+1 words, objects are
n+3 words for a class with n fields, and classes are n+2 words for n
methods, but some of those "+1"s could be "+2"s (or +2s being +3s,
etc).

Robby

On Tue, Jan 5, 2010 at 10:33 AM, Dave Gurnell <d.j.gurnell at gmail.com> wrote:
> I remember getting zeroes intermittently when I tried using current-memory-use with a custodian before (about a year ago).
>
> This is for a web app, so there is a custodian structure already in place. It looks like (current-memory-use (current-custodian)) returns a fairly constant value that changes occasionally and by large increments (every 20 or 30 page loads). Perhaps this is blocks of allocated memory rather than precise consumption?
>
> I've written a little combinator library that traverses the relevant structures and estimates their size directly... this is undoubtedly a naive approach, especially as I have no idea about PLT internals and I haven't done any C level programming in years.
>
> I'm only trying to get a rough idea of memory use, to point out any pages with gross inefficiencies. The naive approach may be enough for this.
>
> -- Dave
>
> On 5 Jan 2010, at 16:23, Robby Findler wrote:
>
>> It doesn't look like it, but I may be doing something wrong (the
>> printf is just there to be usre that the object is still in used).
>>
>> (let ([c (make-custodian)])
>>    (parameterize ([current-custodian c])
>>      (let ([obj (cons 1 2)])
>>        (collect-garbage)
>>        (begin0
>>          (current-memory-use c)
>>          (printf "~s\n" obj)))))
>>
>> This produces 0 for me.
>>
>> Robby
>>
>> On Tue, Jan 5, 2010 at 10:18 AM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>>> Could you create it in a new custodian and measure that custodian memory usage?
>>>
>>> Jay
>>>
>>> On Tue, Jan 5, 2010 at 8:00 AM, Robby Findler
>>> <robby at eecs.northwestern.edu> wrote:
>>>> You can create a bunch of them and compare the amount of memory used
>>>> before and afterwards (and divide).
>>>>
>>>> Robby
>>>>
>>>> On Tue, Jan 5, 2010 at 8:53 AM, Dave Gurnell <d.j.gurnell at gmail.com> 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
>>>>>
>>>>> I saw the sizeof package on PLaneT but it looks like that's for FFI structures, not scheme ones.
>>>>>
>>>>> Many thanks,
>>>>>
>>>>> -- Dave
>>>>>
>>>>> _________________________________________________
>>>>>  For list-related administrative tasks:
>>>>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>>>>
>>>> _________________________________________________
>>>>  For list-related administrative tasks:
>>>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>>>
>>>
>>>
>>>
>>> --
>>> Jay McCarthy <jay at cs.byu.edu>
>>> Assistant Professor / Brigham Young University
>>> http://teammccarthy.org/jay
>>>
>>> "The glory of God is Intelligence" - D&C 93
>>>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.