From: Jeffrey H. <jef...@aj...> - 2000-08-31 18:36:21
|
> From: George Howlett [mailto:ga...@si...] ... > I've never run into this problem and at some point it becomes special > purpose enough to require a custom solution (e.g. allocate your own > buffer). I don't know if this a practical or theoretical problem? > Why does anyone need a 1 Gig string? > > But if one still wants to handle this within Tcl, I have a slightly > different tact. When realloc fails, pull back the size. It can fail > when you can't allocate even the extra space needed. > > growth = oldSize + appendSize; > do { > newSize = oldSize + appendSize + growth; > newMem = realloc(oldMem, newSize); > growth /= 2; > if (growth < appendSize) { > break; > } > } while (newMem == NULL); > > At least this way the penalty is all on the special case, not general > usage. This was already mentioned in the newsgroup thread, and I reiterated it here yesterday. To repeat the problems with that: The other suggestion in the thread was a fall-back allocation mechanism, whereby one still goes for *2 all the time, until malloc says, "No". Then we would try for just what we need (or a bit more), and see if that works. However, that requires changing around the ckalloc routines, because they panic by default when malloc returns NULL. You'd have to create some sort of alternative like: bytes = (char *) ckallocEx(howMuchIWant, howMuchINeed); Jeffrey Hobbs Tcl Ambassador ho...@Aj... Ajuba Solutions (née Scriptics) -- The TclCore mailing list is sponsored by Ajuba Solutions To unsubscribe: email tcl...@aj... with the word UNSUBSCRIBE as the subject. |