Hi.
I want class with 'log'.
I mean when an instance of class 'foo' (with
per-instance slot 'id') is GC-ed 'finalizer'
should add that 'id' slot's value to data
structure (for example: to a list) bound to
per-class slot 'log'. Or smthing like that.
Example will be very appreciated :)
TIA.
+ Szymon 'tichy' <········@glombraz.org>:
> I want class with 'log'.
>
> I mean when an instance of class 'foo' (with
> per-instance slot 'id') is GC-ed 'finalizer'
> should add that 'id' slot's value to data
> structure (for example: to a list) bound to
> per-class slot 'log'. Or smthing like that.
Have you looked at section 6.1 in the SBCL manual?
Not that I think what you ask is a very good idea, due to the
unpredictable nature of when objects are collected. You are probably
better off keeping track of when objects are no longer needed, then
logging the fact and invalidating them somehow so further attempts at
using them signals an error. (Probably, you're really better off
doing nothing of the sort. It all depends on what problem you're
really trying to solve.)
Oh, and notice that section 6.1 in the manual is part of chapter 6,
entitled "Beyond the ANSI Standard". Which ought to indicate that
there is no portable way to do what you ask, if that bothers you.
Maybe it should.
--
* Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
when there is no ground whatsoever for supposing it is true.
-- Bertrand Russell
Harald Hanche-Olsen wrote:
> + Szymon 'tichy' <········@glombraz.org>:
>
>> I want class with 'log'.
>>
>> I mean when an instance of class 'foo' (with
>> per-instance slot 'id') is GC-ed 'finalizer'
>> should add that 'id' slot's value to data
>> structure (for example: to a list) bound to
>> per-class slot 'log'. Or smthing like that.
>
> Have you looked at section 6.1 in the SBCL manual?
Yes. But... there was something wrong with output,
so my example failed. I gave it second try,
and it worked :)
CL-USER> (defclass test () ())
#<STANDARD-CLASS TEST>
CL-USER> (defparameter *test* (make-instance 'test))
*TEST*
CL-USER> (gc :full t) ; no thing should happen
NIL
CL-USER> (prog1 :please-work
(sb-ext:finalize *test* (lambda () (princ "more or less... it works."))))
:PLEASE-WORK
CL-USER> (gc :full t) ; no thing should happen
NIL
CL-USER> (setq *test* '|Sooner or later, everyone is going to die.|)
|Sooner or later, everyone is going to die.|
CL-USER> (gc :full t)
more or less... it works.
NIL
> [...] (Probably, you're really better off
> doing nothing of the sort. It all depends on what problem you're
> really trying to solve.)
I have two ideas. One is evil. Second idea is to use finalizer
to test (2 logs, one will use finalizer, if they are going to
be equal then (probably) everything should be ok).
Regards, Szymon.