Reuse, not rework
Home

License Awareness



Highly Reusable Software

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


NAME

librock_FSILnew - Create a fixed-size item list (FSIL). Integer indexed storage for fixed-size items.
librock_FSILdelete - Deallocate all memory used by an FSIL.
librock_FSILpoint - Return a temporary pointer to an indexed item.
librock_FSILinsertAt - Insert an item at index, or end of list.
librock_FSILinsertcopyAt - Insert and initialize an item at index, or end of list.
librock_FSILdeleteAt - Delete an item at index
librock_FSILitemcount - Return number of items in an librock_FSIL.

#License - #Source code - #Example Use -

SYNOPSIS

#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)

DESCRIPTION

These routines implement storage for a list of fixed-size items accessed by integer index. Items can be inserted and deleted from the list, which may move items around in memory. Memory allocations using malloc() are "pooled" so that a block of malloc()ed memory is used to store more than one item.

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

USES

  malloc()
  free()
  memmove()
  memcpy()


LICENSE

  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

Source Code

./exec/struct/fsil.c (implementation, plus source of this manual page)

Tests and Supported Platform Types

This is a representative sample. Librock code is highly portable. For a particular platform not reported here, request paid support

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)


This software is part of Librock

Rapid reuse, without rework. Details
This page copyright (C) 2002-2003 Forrest J. Cavalier III, d-b-a Mib Software, Saylorsburg PA 18353, USA

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.