xorp

freelist.h

00001 #ifndef freelist_h
00002 #define freelist_h
00003 
00004 /*
00005  * Copyright (c) 2000, 2001 by Martin C. Shepherd.
00006  * 
00007  * All rights reserved.
00008  * 
00009  * Permission is hereby granted, free of charge, to any person obtaining a
00010  * copy of this software and associated documentation files (the
00011  * "Software"), to deal in the Software without restriction, including
00012  * without limitation the rights to use, copy, modify, merge, publish,
00013  * distribute, and/or sell copies of the Software, and to permit persons
00014  * to whom the Software is furnished to do so, provided that the above
00015  * copyright notice(s) and this permission notice appear in all copies of
00016  * the Software and that both the above copyright notice(s) and this
00017  * permission notice appear in supporting documentation.
00018  * 
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00020  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
00022  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
00023  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
00024  * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
00025  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
00026  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
00027  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00028  * 
00029  * Except as contained in this notice, the name of a copyright holder
00030  * shall not be used in advertising or otherwise to promote the sale, use
00031  * or other dealings in this Software without prior written authorization
00032  * of the copyright holder.
00033  */
00034 
00035 /*
00036  * This module provides a memory allocation scheme that helps to
00037  * prevent memory fragmentation by allocating large blocks of
00038  * fixed sized objects and forming them into a free-list for
00039  * subsequent allocations. The free-list is expanded as needed.
00040  */
00041 typedef struct FreeList FreeList;
00042 
00043 /*
00044  * Allocate a new free-list from blocks of 'blocking_factor' objects of size
00045  * node_size. The node_size argument should be determined by applying
00046  * the sizeof() operator to the object type that you intend to allocate from
00047  * the freelist.
00048  */
00049 FreeList *_new_FreeList(const char *caller, size_t node_size,
00050             unsigned blocking_factor);
00051 
00052 /*
00053  * If it is known that none of the nodes currently allocated from
00054  * a freelist are still in use, the following function can be called
00055  * to return all nodes to the freelist without the overhead of
00056  * having to call del_FreeListNode() for every allocated node. The
00057  * nodes of the freelist can then be reused by future callers to
00058  * new_FreeListNode().
00059  */
00060 void _rst_FreeList(FreeList *fl);
00061 
00062 /*
00063  * Delete a free-list.
00064  */
00065 FreeList *_del_FreeList(const char *caller, FreeList *fl, int force);
00066 
00067 /*
00068  * Determine the number of nodes that are currently allocated.
00069  */
00070 long _busy_FreeListNodes(FreeList *fl);
00071 
00072 /*
00073  * Allocate a new object from a free-list.
00074  */
00075 void *_new_FreeListNode(FreeList *fl);
00076 
00077 /*
00078  * Return an object to the free-list that it was allocated from.
00079  */
00080 void *_del_FreeListNode(FreeList *fl, void *object);
00081 
00082 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations