# kjs Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# collector.h

    00001 // -*- c-basic-offset: 2 -*-
    00002 /*
    00003  *  This file is part of the KDE libraries
    00004  *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
    00005  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    00006  *
    00007  *  This library is free software; you can redistribute it and/or
    00008  *  modify it under the terms of the GNU Lesser General Public
    00009  *  License as published by the Free Software Foundation; either
    00010  *  version 2 of the License, or (at your option) any later version.
    00011  *
    00012  *  This library is distributed in the hope that it will be useful,
    00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015  *  Lesser General Public License for more details.
    00016  *
    00017  *  You should have received a copy of the GNU Lesser General Public
    00018  *  License along with this library; if not, write to the Free Software
    00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00020  *
    00021  *  $Id: collector.h,v 1.17.2.1 2003/05/17 11:19:24 mueller Exp $
    00022  */
    00023
    00024 #ifndef _KJSCOLLECTOR_H_
    00025 #define _KJSCOLLECTOR_H_
    00026
    00027 // KJS_MEM_LIMIT and KJS_MEM_INCREMENT can be tweaked to adjust how the
    00028 // garbage collector allocates memory. KJS_MEM_LIMIT is the largest # of objects
    00029 // the collector will allow to be present in memory. Once this limit is reached,
    00030 // a running script will get an "out of memory" exception.
    00031 //
    00032 // KJS_MEM_INCREMENT specifies the amount by which the "soft limit" on memory is
    00033 // increased when the memory gets filled up. The soft limit is the amount after
    00034 // which the GC will run and delete unused objects.
    00035 //
    00036 // If you are debugging seemingly random crashes where an object has been deleted,
    00037 // try setting KJS_MEM_INCREMENT to something small, e.g. 300, to force garbage
    00038 // collection to happen more often, and disable the softLimit increase &
    00039 // out-of-memory testing code in Collector::allocate()
    00040
    00041 #define KJS_MEM_LIMIT 500000
    00042 #define KJS_MEM_INCREMENT 1000
    00043
    00044 #include <stdlib.h>
    00045
    00046 // for DEBUG_*
    00047 #include "value.h"
    00048 #include "object.h"
    00049 #include "types.h"
    00050 #include "interpreter.h"
    00051
    00052 namespace KJS {
    00053
    00054   class CollectorBlock;
    00055
    00059   class Collector {
    00060     // disallow direct construction/destruction
    00061     Collector();
    00062   public:
    00073     static void* allocate(size_t s);
    00078     static bool collect();
    00079     static int size() { return filled; }
    00080     static bool outOfMemory() { return memLimitReached; }
    00081
    00082 #ifdef KJS_DEBUG_MEM
    00083
    00086     static void finalCheck();
    00090     static bool collecting;
    00091 #endif
    00092   private:
    00093     static CollectorBlock* root;
    00094     static CollectorBlock* currentBlock;
    00095     static unsigned long filled;
    00096     static unsigned long softLimit;
    00097     static bool memLimitReached;
    00098     enum { BlockSize = 100 };
    00099   };
    00100
    00101 }
    00102
    00103 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:08:18 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001