
6.4 The Resource Facility
Syntax:clear-resource resource
clear-resource removes all existing objects from the specified resource.
resource-allocate for the specified resource create new objects.
resource-allocate removes any pointers from the resource to the object before allocating that object, and the function resource-deallocate restores the pointers when the object is deallocated. Thus, the Resource Facility does not maintain any pointers to objects that are currently in use.
clear-resource removes all pointers to an object that the resource maintains.Thus, you can include a call toclear-resource in functions that invoke a garbage collection to allow objects that are not in use to be reclaimed.
resource-allocate, resource-deallocate
Syntax:make-resource name&key :constructor :initial-copies:initialization-function :cleanup-function :initial-args
make-resource creates and returns a resource object.
:constructorresource-allocate. The constructor function that you supply must accept the arguments specified in the args argument toresource-allocate. It returns a resource object; it should not returnnil.
:initial-copies:initial-args argument list when making objects. If the specified constructor function is a function of no arguments, you do not need to supply the:initial-args keyword option.
:initial-copies argument, the resource is created empty. The first time that the functionresource-allocate is invoked, the constructor function makes an object to allocate.
:initialization-functionresource-allocate. The initialization function is not called on objects that are created by the constructor function.
:cleanup-function resource-deallocate returns an object to the resource. The function that you specify must take one argument, the object being deallocated.
:initial-args:initial-copies keyword argument. If the constructor function takes no arguments or if you have not specified a value for:initial-copies, you do not need to supply this list.
resource-allocate
Syntax:resource-allocate resource&rest args
resource-allocate allocates an object from the specified resource and sets any pointer to the object in the resource tonil.
resource-allocate callsmake-resource and passes the arguments specified by args to the constructor function. The object returned by the constructor function is returned byresource-allocate.
resource-allocate passes the specified args to the initialization function ofmake-resource before allocating the object.
make-resource, resource-deallocate
Syntax:resource-deallocate resource object
resource-deallocate returns an object to the specified resource.
resource-deallocate cannot check whether the specified object was allocated from the specified resource.
resource-allocate, clear-resource
Syntax:using-resource (object-var resource&rest args) {form}*
using-resource allocates an object from the specified resource, binds a variable to it, and then invokes a Common Lispunwind-protect special form.
unwind-protect special form has been executed,using-resource checks the value of this variable. If the value isnil, the object is not returned to the resource; otherwise, the object is deallocated.
nil.
resource-allocate to allocate the object before the execution of the form arguments.

Generated with Harlequin WebMaker