From: Eric M. <er...@aj...> - 2000-08-30 01:41:36
|
(apologies for the verbosity of this message) Gerhard Hintermayer sent me a patch to adjust the way that the Tcl core allocates memory for strings when growing them (via an append, for example). Formerly, the growth algorithm was: newsize = 2 * (oldsize + appendsize) Now, the growth algorithm is: if (oldsize + appendsize >= TCL_GROWTH_LARGE_STRING) newsize = oldsize + (2 * appendsize) + TCL_GROWTH_MIN_ALLOC else newsize = 2 * (oldsize + appendsize) endif TCL_GROWTH_LARGE_STRING defaults to 1 megabyte; TCL_GROWTH_MIN_ALLOC defaults to 1 kilobyte, and is included to efficiently handle repeated small appends to a large string. The primary goal of this change was to increase the amount of memory that Tcl could allocate. With the original algorithm, if you had a string that was about 1/2 of available memory, you could not add to it anymore, because it would try to allocate more than all of the available memory. With the new algorithm, you can effectively allocate all of available memory (depending on how you are growing the string -- once you get close to the maximum, you will have to append progressively smaller amounts, but you should be able to expand to fill all memory, if neccessary). However, a nice side benefit of the new algorithm is that it boosts core performance, across the board. You can run the Tcl benchmark suite to see all the improvements; I have included just the [append] benchmarks here as these show the improvements most dramatically, I believe: 000 VERSIONS: 1:8.4a2 2:8.4a1 001 STR append 49 65 002 STR append (1KB + 1KB) 42 45 003 STR append (10KB + 1KB) 130 132 004 STR append (1MB + 2b * 1000) 13163 21765 005 STR append (1MB + 1KB) 7977 16320 006 STR append (1MB + 1KB * 20) 8258 16497 007 STR append (1MB + 1MB * 3) 33898 40935 008 STR append (1MB + 1MB * 5) 41330 81164 END VERSIONS: 1:8.4a2 2:8.4a1 Here, 8.4a2 includes the patch; 8.4a1 has the original behavior. Nice work, Gerhard! Eric Melski The Other Tcl Guy ericm at ajubasolutions.com Ajuba Solutions -- The TclCore mailing list is sponsored by Ajuba Solutions To unsubscribe: email tcl...@aj... with the word UNSUBSCRIBE as the subject. |