Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

chunkallocator.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *  @file  chunkallocator.h
00003  *  @brief chunkallocator Header File.
00004  *
00005  *  @date   : 15-08-03 00:45
00006  *  @author : Pedro Ortega C. <peortega@dcc.uchile.cl>
00007  *  Copyright  2003  Pedro Ortega C.
00008  ****************************************************************************/
00009 /*
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023  */
00024 
00025 
00026 #ifndef _CHUNKALLOCATOR_H_
00027 #define _CHUNKALLOCATOR_H_
00028 
00029 
00030 
00031 /******************************************/
00032 /* Macros and Definitions                 */
00033 /******************************************/
00034 
00035 /**
00036  * @brief Minimum of Chunkblock.
00037  * @ingroup chunkallocator_doc
00038  *
00039  * This is the size of the first chunkblock to be created. If full, subsequent
00040  * chunkblocks double its predecessor's size.
00041  */
00042 #define CHUNKBLOCK_MINSIZE 32
00043 
00044 
00045 
00046 /******************************************/
00047 /* Typedefs                               */
00048 /******************************************/
00049 
00050 /**
00051  * @brief Chunkblock.
00052  * @ingroup chunkallocator_doc
00053  *
00054  * The structure that holds the information of a single chunkblock. The begin
00055  * and endpointer delimite the chunkblock.
00056  */
00057 typedef struct
00058 {
00059     unsigned char *beginptr;
00060     unsigned char *endptr;
00061 } chunkblock;
00062 
00063 /**
00064  * @brief Chunkallocator structure.
00065  * @ingroup chunkallocator_doc
00066  *
00067  * This is the structure that makes a Chunkallocator. Its fields hold the
00068  * information for managing the memory.
00069  */
00070 typedef struct
00071 {
00072     size_t          binsize;     /**< The size of the bins.                   */
00073     size_t          allocated;   /**< The number of currently allocated bins. */
00074     size_t          deallocated; /**< The number of the currently deallocated
00075                                       bins.                                   */
00076     unsigned char **nextdealloc; /**< Pointer to the first deallocated bin.   */
00077     unsigned char  *nextfree;    /**< Pointer to the next free bin.           */
00078     chunkblock     *cblock;      /**< Pointer to currently used chunkblock.   */
00079     chunkblock     *memblocks;   /**< Array of chunkblocks.                   */
00080 } chunkallocator;
00081 
00082 
00083 
00084 /******************************************/
00085 /* Public Interface                       */
00086 /******************************************/
00087 
00088 chunkallocator *
00089 chunkallocator_new (size_t binsize);
00090 
00091 void
00092 chunkallocator_destroy (chunkallocator *a);
00093 
00094 void *
00095 chunkallocator_alloc (chunkallocator *a);
00096 
00097 void
00098 gnn_chunkallocator_free (chunkallocator *a, void *memblock);
00099 
00100 
00101 #endif /* _GNN_CHUNKALLOCATOR_H_ */
00102 

Generated on Sun Jun 13 20:50:11 2004 for libgnn Gradient Retropropagation Machine Library by doxygen1.2.18