| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

mem_scavenger

#include "sflmem.h"
int
mem_scavenger (
    scavenger scav_fct,                 /*  File to dump display to          */
    void    * scav_arg
)

Synopsis

Registers a memory scavenger function. A memory scavenger function is an application function that is invoked by mem alloc () when memory is exhausted, so that unused application objects can be released. This allows you to allocate large amounts of memory -- for instance for caches -- and then release them when memory runs short. When you register a scavenger function you may provide a void * argument; this is passed back to the scavenger if it is ever invoked. The scavenger function returns TRUE if it could release some memory, otherwise it returns FALSE. Note that there is no way to unregister such a function. Furthermore, a scavenger function should not itself allocate any new memory, unless it can definitely free excess memory first. Scavenger functions are called in an unspecified order. Returns 0 if the scavenger function could be registered, -1 if not. There is no limit to the number of scavenger functions you can register, except available memory. The same scavenger function can be registered several times.

Source Code - (sflmem.c)

{
    SCAVFCT
        *scavfct;                       /*  Allocated registry function      */

    /*  Allocate an SCAVFCT block and attach it to the scavfcts list         */
    list_create (scavfct, sizeof (SCAVFCT));
    if (scavfct == NULL)
        return (-1);
    list_relink_before (scavfct, &scavfcts);

    scavfct-> scav_fct = scav_fct;
    scavfct-> scav_arg = scav_arg;
    return (0);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation