xorp

stringrp.h

00001 #ifndef stringrp_h
00002 #define stringrp_h
00003 /*
00004  * Copyright (c) 2000, 2001 by Martin C. Shepherd.
00005  * 
00006  * All rights reserved.
00007  * 
00008  * Permission is hereby granted, free of charge, to any person obtaining a
00009  * copy of this software and associated documentation files (the
00010  * "Software"), to deal in the Software without restriction, including
00011  * without limitation the rights to use, copy, modify, merge, publish,
00012  * distribute, and/or sell copies of the Software, and to permit persons
00013  * to whom the Software is furnished to do so, provided that the above
00014  * copyright notice(s) and this permission notice appear in all copies of
00015  * the Software and that both the above copyright notice(s) and this
00016  * permission notice appear in supporting documentation.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
00021  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
00022  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
00023  * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
00024  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
00025  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
00026  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00027  * 
00028  * Except as contained in this notice, the name of a copyright holder
00029  * shall not be used in advertising or otherwise to promote the sale, use
00030  * or other dealings in this Software without prior written authorization
00031  * of the copyright holder.
00032  */
00033 
00034 /*
00035  * StringGroup objects provide memory for modules that need to
00036  * allocate lots of small strings without needing to free any of them
00037  * individually, but rather is happy to free them all at the same
00038  * time. Taking advantage of these properties, StringGroup objects
00039  * avoid the heap fragmentation that tends to occur when lots of small
00040  * strings are allocated directly from the heap and later free'd. They
00041  * do this by allocating a list of large character arrays in each of
00042  * which multiple strings are stored. Thus instead of allocating lots
00043  * of small strings, a few large character arrays are allocated. When
00044  * the strings are free'd on mass, this list of character arrays is
00045  * maintained, ready for subsequent use in recording another set of
00046  * strings.
00047  */
00048 typedef struct StringGroup StringGroup;
00049 
00050 /*
00051  * The following constructor allocates a string-allocation object.
00052  * The segment_size argument specifies how long each string segment
00053  * array should be. This should be at least 10 times the length of
00054  * the average string to be recorded in the string group, and
00055  * sets the length of the longest string that can be stored.
00056  */
00057 StringGroup *_new_StringGroup(int segment_size);
00058 
00059 /*
00060  * Delete all of the strings that are currently stored by a specified
00061  * StringGroup object.
00062  */
00063 void _clr_StringGroup(StringGroup *sg);
00064 
00065 /*
00066  * Make a copy of the specified string, returning a pointer to
00067  * the copy, or NULL if there was insufficient memory. If the
00068  * remove_escapes argument is non-zero, backslashes that escape
00069  * other characters will be removed.
00070  */
00071 char *_sg_store_string(StringGroup *sg, const char *string, int remove_escapes);
00072 
00073 /*
00074  * Allocate memory for a string of a given length.
00075  */
00076 char *_sg_alloc_string(StringGroup *sg, int length);
00077 
00078 /*
00079  * Delete a StringGroup object (and all of the strings that it
00080  * contains).
00081  */
00082 StringGroup *_del_StringGroup(StringGroup *sg);
00083 
00084 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations