Changeset 47 for trunk/src/helpers/linklist.c
- Timestamp:
- Mar 13, 2001, 1:20:46 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/linklist.c
r38 r47 15 15 * <B>Usage:</B> 16 16 * 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 * 17 22 * Each list item is stored in a LISTNODE structure, which in 18 23 * 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 + 21 33 + // fill the list 22 34 + PLINKLIST pll = lstCreate(TRUE or FALSE); 23 35 + while ... 24 36 + { 25 + PYOURDATA pYourData = ...37 + PYOURDATA pYourData = (PYOURDATA)malloc(sizeof(YOURDATA)); 26 38 + lstAppendItem(pll, pYourData); // store the data in a new node 27 39 + } … … 56 68 57 69 /* 58 * Copyright (C) 1997-200 0Ulrich Mller.70 * Copyright (C) 1997-2001 Ulrich Mller. 59 71 * This file is part of the "XWorkplace helpers" source package. 60 72 * This is free software; you can redistribute it and/or modify … … 120 132 /* 121 133 *@@ lstInit: 122 * this initializes a given linked list. 134 * this initializes a given LINKLIST structure. 135 * 123 136 * 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: 128 143 + 129 144 + LINKLIST llWhatever; … … 138 153 * invoked on list items automatically in lstClear, 139 154 * 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. 155 172 * 156 173 * Note: You better call lstInit only once per list, … … 185 202 * when the list was initialized (lstInit), free() 186 203 * will be invoked on all data item pointers also. 187 * See the remarks there.204 * See the remarks for lstInit. 188 205 * 189 206 * Returns FALSE only upon errors, e.g. because … … 259 276 * using lstFree. 260 277 * 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. 268 279 * 269 280 * Returns NULL upon errors. … … 298 309 * when the list was created (lstCreate), free() 299 310 * will be invoked on all data item pointers also. 300 * See the remarks there.301 * 302 * This must only be used with dynamiclists created311 * See the remarks for lstInit. 312 * 313 * This must only be used with heap lists created 303 314 * with lstCreate. 304 315 */
Note:
See TracChangeset
for help on using the changeset viewer.