From: Bob Felts
Subject: Implementation costs...
Date: 
Message-ID: <1ifb0ue.en36r9ft7lmoN%wrf3@stablecross.com>
Perlis quipped, "A Lisp programmer knows the value of everything, but
the cost of nothing."

With this is mind, is there a way (even if implementation dependent) of
querying the amount of memory used by an object?  FWIW, I'm using SBCL.

From: Barry Margolin
Subject: Re: Implementation costs...
Date: 
Message-ID: <barmar-5085A7.22065512042008@newsgroups.comcast.net>
In article <··························@stablecross.com>,
 ····@stablecross.com (Bob Felts) wrote:

> Perlis quipped, "A Lisp programmer knows the value of everything, but
> the cost of nothing."
> 
> With this is mind, is there a way (even if implementation dependent) of
> querying the amount of memory used by an object?  FWIW, I'm using SBCL.

The implementation documentation may provide details of how much memory 
is used by each type of object.

You can also use the ROOM function.  Run it before and after allocating 
the object.  You should probably also run it twice in a row with nothing 
in between -- the function itself may cons, and this will give you a 
baseline to subtract out.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Bob Felts
Subject: Re: Implementation costs...
Date: 
Message-ID: <1ifb28q.5ofei11bx9vkqN%wrf3@stablecross.com>
Barry Margolin <······@alum.mit.edu> wrote:

> In article <··························@stablecross.com>,
>  ····@stablecross.com (Bob Felts) wrote:
> 
> > Perlis quipped, "A Lisp programmer knows the value of everything, but
> > the cost of nothing."
> > 
> > With this is mind, is there a way (even if implementation dependent) of
> > querying the amount of memory used by an object?  FWIW, I'm using SBCL.
> 
> The implementation documentation may provide details of how much memory
> is used by each type of object.
> 
> You can also use the ROOM function.  Run it before and after allocating
> the object.  You should probably also run it twice in a row with nothing
> in between -- the function itself may cons, and this will give you a 
> baseline to subtract out.

Thanks, Barry.   This will help satisfy my curiosity.
From: Rob Warnock
Subject: Re: Implementation costs...
Date: 
Message-ID: <r4idnYxrN_z0TZzVnZ2dnUVZ_veinZ2d@speakeasy.net>
Barry Margolin  <······@alum.mit.edu> wrote:
+---------------
| You can also use the ROOM function.  ...
+---------------

Also be sure to try all three ANSI-defined variants,
which might give usefully-different amounts of information:

    (room nil)
    (room :default)   ; Or simply (room)
    (room t)


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Pascal Bourguignon
Subject: Re: Implementation costs...
Date: 
Message-ID: <877if232w2.fsf@thalassa.informatimago.com>
····@stablecross.com (Bob Felts) writes:

> Perlis quipped, "A Lisp programmer knows the value of everything, but
> the cost of nothing."
>
> With this is mind, is there a way (even if implementation dependent) of
> querying the amount of memory used by an object?  FWIW, I'm using SBCL.

The problem is that since in lisp we have a garbage collector, we
don't have to think about freeing memory, so we can easily share parts
of our data structures.

The space cost is then shared amongst several datastructures, thus
divided by the number of use.  Asymptotically, it's 0.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"Logiciels libres : nourris au code source sans farine animale."
From: Bob Felts
Subject: Re: Implementation costs...
Date: 
Message-ID: <1ifccpv.51bmvp1liwzmqN%wrf3@stablecross.com>
Pascal Bourguignon <···@informatimago.com> wrote:

> ····@stablecross.com (Bob Felts) writes:
> 
> > Perlis quipped, "A Lisp programmer knows the value of everything, but
> > the cost of nothing."
> >
> > With this is mind, is there a way (even if implementation dependent) of
> > querying the amount of memory used by an object?  FWIW, I'm using SBCL.
> 
> The problem is that since in lisp we have a garbage collector, we
> don't have to think about freeing memory, so we can easily share parts
> of our data structures.
> 
> The space cost is then shared amongst several datastructures, thus
> divided by the number of use.  Asymptotically, it's 0.

But practically is another story. In my case, I'm creating a list which
holds the contents of a file (e.g. 36MB) and I'm curious about how
implementation choices affect memory use.
From: D Herring
Subject: Re: Implementation costs...
Date: 
Message-ID: <b-udndNPkaupb5_VnZ2dnUVZ_qainZ2d@comcast.com>
Bob Felts wrote:
> Pascal Bourguignon <···@informatimago.com> wrote:
> 
>> ····@stablecross.com (Bob Felts) writes:
>>
>>> Perlis quipped, "A Lisp programmer knows the value of everything, but
>>> the cost of nothing."
>>>
>>> With this is mind, is there a way (even if implementation dependent) of
>>> querying the amount of memory used by an object?  FWIW, I'm using SBCL.
>> The problem is that since in lisp we have a garbage collector, we
>> don't have to think about freeing memory, so we can easily share parts
>> of our data structures.
>>
>> The space cost is then shared amongst several datastructures, thus
>> divided by the number of use.  Asymptotically, it's 0.
> 
> But practically is another story. In my case, I'm creating a list which
> holds the contents of a file (e.g. 36MB) and I'm curious about how
> implementation choices affect memory use.

For things which use large chunks of memory in sbcl on linux, I call 
(gc :full t) and then check the unix top command -- before and after 
allocating or freeing memory in lisp.  This reliably detects memory 
leaks both inside and outside lisp (e.g. in CFFI interfaces).  Others 
already pointed you to ROOM; usage is generally similar to top, but it 
stays inside lisp.

For a somewhat rougher guesstimate, sbcl's implementation of TIME can 
be helpful -- though it includes memory that is gc'd.

CL-USER> (time (progn (make-array '(100 200))
		      nil))
Evaluation took:
   0.0 seconds of real time
   0.0 seconds of user run time
   0.0 seconds of system run time
   0 calls to %EVAL
   0 page faults and
   160,016 bytes consed.
NIL

- Daniel
From: Edi Weitz
Subject: Re: Implementation costs...
Date: 
Message-ID: <uej9akxv5.fsf@agharta.de>
On Sat, 12 Apr 2008 22:00:46 -0400, ····@stablecross.com (Bob Felts) wrote:

> With this is mind, is there a way (even if implementation dependent)
> of querying the amount of memory used by an object?

That's implementation-dependent.

  http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-211.htm

Edi.

-- 

European Common Lisp Meeting, Amsterdam, April 19/20, 2008

  http://weitz.de/eclm2008/

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Leonardo Varuzza
Subject: Re: Implementation costs...
Date: 
Message-ID: <a3598bf8-a115-46ee-a173-9b66aebb6c6a@a23g2000hsc.googlegroups.com>
On Apr 13, 4:38 am, Edi Weitz <········@agharta.de> wrote:
> On Sat, 12 Apr 2008 22:00:46 -0400, ····@stablecross.com (Bob Felts) wrote:
> > With this is mind, is there a way (even if implementation dependent)
> > of querying the amount of memory used by an object?
>
> That's implementation-dependent.
>
>  http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-211.htm
>
> Edi.
>
> --
>
> European Common Lisp Meeting, Amsterdam, April 19/20, 2008
>
>  http://weitz.de/eclm2008/
>
> Real email: (replace (subseq ·········@agharta.de" 5) "edi")

I tried to made a find-object-size in SBCL looking at the source of
room. I founded the function sb-vm::map-allocated-objects which inform
the the memory used by all the objects. I can't figure out how to get
the pointers of a specific object tree and sum the memory usage of
those.
From: Bob Felts
Subject: Re: Implementation costs...
Date: 
Message-ID: <1ifccyv.1gicmpxds0apsN%wrf3@stablecross.com>
Edi Weitz <········@agharta.de> wrote:

> On Sat, 12 Apr 2008 22:00:46 -0400, ····@stablecross.com (Bob Felts) wrote:
> 
> > With this is mind, is there a way (even if implementation dependent)
> > of querying the amount of memory used by an object?
> 
> That's implementation-dependent.
> 
>   http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-211.htm
> 

One of these days I'll have $1500 to spend on LW.  I've been itching for
some time, now...