Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

mempool.h

Go to the documentation of this file.
00001 /* $Id$ */
00002 /*
00003 ** Copyright (C) 2002 Martin Roesch <roesch@sourcefire.com>
00004 **
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 **
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 **
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 
00021 #ifndef _MEMPOOL_H
00022 #define _MEMPOOL_H
00023 
00024 #include "sf_sdlist.h"
00025 
00026 typedef unsigned int PoolCount;
00027 
00028 typedef struct _MemBucket
00029 {
00030     SDListItem *key;
00031     int used;
00032     void *data;
00033 } MemBucket;
00034 
00035 typedef struct _MemPool
00036 {
00037     void **datapool; /* memory buffer for MemBucket->data */
00038     
00039     MemBucket *bucketpool; /* memory buffer */
00040 
00041     SDListItem *listpool; /* list of things to use for memory bufs */
00042 
00043     PoolCount free; /*  free block count */
00044     PoolCount used;  /* used block count */
00045 
00046     PoolCount total;
00047     
00048     sfSDList free_list;
00049     sfSDList used_list;
00050     
00051     size_t obj_size;    
00052 } MemPool;
00053 
00054 int mempool_init(MemPool *mempool, PoolCount num_objects, size_t obj_size);
00055 int mempool_destroy(MemPool *mempool);
00056 MemBucket *mempool_alloc(MemPool *mempool);
00057 void mempool_free(MemPool *mempool, MemBucket *obj);
00058 
00059 #endif /* _MEMPOOL_H */
00060 
00061 

Generated on Sun May 14 14:51:14 2006 by  doxygen 1.4.2