Home
Highly Reusable Software By activity User Interface Text Strings Math Processing
Stored Data
Communications
Hard World File System
|
#License - #Source code - #Example Use -
#include <librock/mstruct.h> struct librock_FSIL_s * librock_body_FSILnew( int isize,int grow,int shrink ); void librock_body_FSILdelete( struct librock_FSIL_s librock_PTR *m ); void * librock_body_FSILpoint( struct librock_FSIL_s librock_PTR *m, long index ); int librock_body_FSILdeleteAt( struct librock_FSIL_s librock_PTR *m, long index ); void * librock_body_FSILinsertcopyAt( struct librock_FSIL_s *m, long index, void *init)
Call librock_FSILnew() to create the FSIL. isize is the item size. If grow is not 0 the blocks requested from malloc() will hold grow number of items. See librock_FSILdeleteAt() for a description of the shrink parameter. The return value is the parameter to give to other librock_FSIL functions.
Call librock_FSILdelete() to free() all memory used by the FSIL obtained by calling librock_FSILnew().
Call librock_FSILpoint() to obtain a pointer to the memory block of the indexed item. The returned pointer is stale (invalid) after the next call to any function which inserts or deletes items (which can move items in memory.)
Call librock_FSILinsertAt() to insert items. A pointer to storage for the indexed item is returned. Use -1 to append at the end of the list. The returned pointer is stale (invalid) after the next call to any function which inserts or deletes items (which can move items in memory.)
Use librock_FSILinsertcopyAt() to insert an item and initialize with a copy of an existing memory block. Use -1 to append at the end of the list.
Call librock_FSILdeleteAt() to delete items. If shrink was not 0 and smaller than grow for the call to librock_FSILnew() then a check is made to coalesce blocks so that there are fewer than shrink items spare in each block. Excess blocks are free()d. librock_FSILdeleteAt returns 0 if successful, non-zero if the index is invalid.
Call librock_FSILitemcount() to count the number of items presently in the FSIL.
Typical use is
#ifdef librock_TYPICAL_USE_FSIL #include <librock/mstruct.h> struct mystruct_s { int member; } *p; struct librock_FSIL_s *pfsil = librock_FSILnew( /*item size=*/ sizeof(*p), /*blocks hold=*/ 16, /*spare per block=*/ 3); p = librock_FSILinsertAt(pfsil,-1); if (!p) { /* ERROR HANDLING */ } p->member = 0; /* ... */ p = librock_FSILinsertcopyAt(pfsil,-1,p); p->member = 1; /* ... */ while(librock_FSILitemcount(pfsil)) { p = (struct mystruct_s *) librock_FSILpoint(pfsil,0); printf("%d\n",p->member); librock_FSILdeleteAt(pfsil,0); } librock_FSILdelete(pfsil); #endif
malloc() free() memmove() memcpy()
Copyright 1998-2002 Forrest J. Cavalier III, http://www.mibsoftware.com Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License text in <librock/license/librock.txt> librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45
librock_FSILdelete passed tests in tfsil (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_FSILdelete passed tests in tfsil_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_FSILdeleteAt passed tests in tfsil (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_FSILdeleteAt passed tests in tfsil_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_FSILinsertAt passed tests in tfsil (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_FSILinsertAt passed tests in tfsil_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_FSILinsertcopyAt passed tests in tfsil (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_FSILinsertcopyAt passed tests in tfsil_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_FSILitemcount passed tests in tfsil (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_FSILitemcount passed tests in tfsil_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_FSILnew passed tests in tfsil (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_FSILnew passed tests in tfsil_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_FSILpoint passed tests in tfsil (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_FSILpoint passed tests in tfsil_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)
Want to help? We welcome comments, patches. -- Need help? Request paid support.