Changeset 21 for trunk/src/helpers/xstring.c
- Timestamp:
- Jan 8, 2001, 6:54:48 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/xstring.c
r18 r21 113 113 114 114 /* 115 *@@category: Helpers\C helpers\String management 115 *@@category: Helpers\C helpers\String management\XStrings (with memory management) 116 * See xstring.c. 116 117 */ 117 118 … … 240 241 free(pxstr->psz); 241 242 memset(pxstr, 0, sizeof(XSTRING)); 243 } 244 245 /* 246 *@@ xstrReserve: 247 * this function makes sure that the specified 248 * XSTRING has at least ulBytes bytes allocated. 249 * 250 * This function is useful if you plan to do 251 * a lot of string replacements or appends and 252 * want to avoid that the buffer is reallocated 253 * with each operation. Before those operations, 254 * call this function to make room for the operations. 255 * 256 * If ulBytes is smaller than the current allocation, 257 * this function does nothing. 258 * 259 * The XSTRING must be initialized before the 260 * call. 261 * 262 * Returns the new total no. of allocated bytes. 263 * 264 *@@added V0.9.7 (2001-01-07) [umoeller] 265 */ 266 267 ULONG xstrReserve(PXSTRING pxstr, 268 ULONG ulBytes) 269 { 270 ULONG cbNeeded = ulBytes; 271 272 if (cbNeeded > pxstr->cbAllocated) 273 { 274 // we need more memory than we have previously 275 // allocated: 276 if (pxstr->cbAllocated) 277 // appendee already had memory: 278 // reallocate 279 pxstr->psz = (PSZ)realloc(pxstr->psz, 280 cbNeeded); 281 else 282 { 283 // appendee has no memory: 284 pxstr->psz = (PSZ)malloc(cbNeeded); 285 *(pxstr->psz) = 0; 286 } 287 288 pxstr->cbAllocated = cbNeeded; 289 // ulLength is unchanged 290 } 291 292 return (pxstr->cbAllocated); 242 293 } 243 294
Note:
See TracChangeset
for help on using the changeset viewer.