[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Tradeoffs with resources
Date: Thu, 20 Sep 90 13:29:18 -0700
From: firstname.lastname@example.org (Jeff Barnett)
I am interested in using resources but can't tell where the break-even
and big-win points are from the documentation. Therefore, the following
(probably too vague) questions:
(1) How much consing does the resource facility do (independent of the froms
I supply) when an object is created?
Very little. The resource itself is an array, and it is grown by chunks
when you've allocated more objects than can fit in the old array. For
minimal consing you should only need a few of the resource elements to be
allocated at any time, and the matcher should be liberal in what it accepts
-- you want most allocations to be satisfied by a free object in the
(2) How much consing does the resource facility do (independent of the froms
I supply) when an object is reallocated?
Hardly any at all. It simply finds the object in the resource and marks it
(3) What are guidelines as to minimum size objects that are good to put
It's difficult to give an answer to this one. Small objects with short
lifetimes will be handled by the EGC (note that the EGC didn't exist when
resources were invented). For precise numbers you should meter your
application with and without resources (this is a good answer to any
question about performance).
(4) How rapidly must the average object be reallocated for using resources
to make sense --- this question assumes that the longer the lifetime
of a single use, the less good the resource idea.
Again, it's very difficult to give an answer out of context; you should
meter. You'd like the time between deallocation and allocation to be
small, so that the free objects in the resource aren't wasting memory.
(5) Is the resource mechanism smart enough to release, to the GC, objects that
are not in use when the GC is prepared to reclaim them, i.e., are objects
not in use copied by the GC because the "resource array" points at them?
You have to tell the resource facility to do this; it doesn't do it by
default. There may be DEFINE-RESOURCE options for this, or maybe you have
to put something on the :BEFORE-GC initialization list. There's a GC
Cleanup option to clean up some resources, so there must be a way to put
your resource on the list of those resources; however, I don't know what it
is offhand (I don't have my documentation handy). Note that these options
apply to dynamic GCs, not ephemeral GCs.
It often makes sense to use areas along with resources. Resource object
constructors probably shouldn't allocate in ephemeral areas, since their
lifetimes aren't consistent with the assumptions that EGC is optimized for.
The general idea is that you use resources when it's cheaper to search for
an acceptable object than to repeatedly allocate them.