Ignore:
Timestamp:
Mar 13, 2001, 1:20:46 PM (24 years ago)
Author:
umoeller
Message:

misc changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/linklist.c

    r38 r47  
    1515 *      <B>Usage:</B>
    1616 *
     17 *      Linked lists are implemented through the LINKLIST structure.
     18 *      This can either be created on the stack or as a global variable
     19 *      (and must then be initialized using lstInit) or from the heap
     20 *      with lstCreate.
     21 *
    1722 *      Each list item is stored in a LISTNODE structure, which in
    1823 *      turn has a pItemData field, which you can use to get your
    19  *      data. So a typical list would be coded like this:
    20  *
     24 *      data. So a typical list would be coded like this (this is
     25 *      a heap list):
     26 *
     27 +
     28 +          typedef struct _YOURDATA
     29 +          {
     30 +              ULONG ulWhatever;
     31 +          } YOURDATA, *PYOURDATA
     32 +
    2133 +          // fill the list
    2234 +          PLINKLIST pll = lstCreate(TRUE or FALSE);
    2335 +          while ...
    2436 +          {
    25  +              PYOURDATA pYourData = ...
     37 +              PYOURDATA pYourData = (PYOURDATA)malloc(sizeof(YOURDATA));
    2638 +              lstAppendItem(pll, pYourData);  // store the data in a new node
    2739 +          }
     
    5668
    5769/*
    58  *      Copyright (C) 1997-2000 Ulrich M”ller.
     70 *      Copyright (C) 1997-2001 Ulrich M”ller.
    5971 *      This file is part of the "XWorkplace helpers" source package.
    6072 *      This is free software; you can redistribute it and/or modify
     
    120132/*
    121133 *@@ lstInit:
    122  *      this initializes a given linked list.
     134 *      this initializes a given LINKLIST structure.
     135 *
    123136 *      This is useful only if you have a static
    124  *      LINKLIST structure in your sources and don't
    125  *      use lstCreate/lstFree to have lists created
    126  *      dynamically. In that case, use this function
    127  *      as follows:
     137 *      LINKLIST structure in your sources (either as
     138 *      a global variable or as a stack variable) and
     139 *      don't use lstCreate/lstFree to have lists created
     140 *      from the heap.
     141 *
     142 *      In that case, use this function as follows:
    128143 +
    129144 +          LINKLIST llWhatever;
     
    138153 *      invoked on list items automatically in lstClear,
    139154 *      lstRemoveNode, and lstRemoveItem.
    140  *      Set this to TRUE if you have created the
    141  *      list items yourself. Set this to FALSE if
    142  *      you're storing other objects, such as numbers
    143  *      or other static items.
    144  *
    145  *      This of course will be a "flat" free(). If
    146  *      you store structures in the list using other
    147  *      heap pointers, auto-free would cause memory leaks.
    148  *
    149  *      Also, auto-free only works if the malloc() that
    150  *      has been used on the list item is in the same C
    151  *      runtime as with the linklist functions. If the
    152  *      caller uses a different runtime (e.g. from a DLL),
    153  *      it can use lstMalloc() for allocating the list
    154  *      item and still use auto-free.
     155 *
     156 *      --  Set this to TRUE if you have created the
     157 *          list items yourself using malloc().
     158 *
     159 *          This of course will be a "flat" free(). If
     160 *          you store structures in the list using other
     161 *          heap pointers, auto-free would cause memory leaks.
     162 *
     163 *          Also, auto-free only works if the malloc() that
     164 *          has been used on the list item is in the same C
     165 *          runtime as with the linklist functions. If the
     166 *          caller uses a different runtime (e.g. from a DLL),
     167 *          it  can use lstMalloc() for allocating the list
     168 *          item and still use auto-free.
     169 *
     170 *      --  Set this to FALSE if you're storing other
     171 *          objects, such as numbers or other static items.
    155172 *
    156173 *      Note: You better call lstInit only once per list,
     
    185202 *      when the list was initialized (lstInit), free()
    186203 *      will be invoked on all data item pointers also.
    187  *      See the remarks there.
     204 *      See the remarks for lstInit.
    188205 *
    189206 *      Returns FALSE only upon errors, e.g. because
     
    259276 *      using lstFree.
    260277 *
    261  *      If (fItemsFreeable == TRUE), free() will be
    262  *      invoked on list items automatically in lstFree,
    263  *      lstRemoveNode, and lstRemoveItem.
    264  *      Set this to TRUE if you have created the
    265  *      list items yourself. Set this to FALSE if
    266  *      you're storing other objects, such as numbers
    267  *      or other static items.
     278 *      See lstInit for the description of fItemsFreeable.
    268279 *
    269280 *      Returns NULL upon errors.
     
    298309 *      when the list was created (lstCreate), free()
    299310 *      will be invoked on all data item pointers also.
    300  *      See the remarks there.
    301  *
    302  *      This must only be used with dynamic lists created
     311 *      See the remarks for lstInit.
     312 *
     313 *      This must only be used with heap lists created
    303314 *      with lstCreate.
    304315 */
Note: See TracChangeset for help on using the changeset viewer.