summaryrefslogtreecommitdiffstats
path: root/generic/tclInt.h
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-05-15 23:08:17 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-05-15 23:08:17 (GMT)
commit6fa73194d556765f6a8dfe33c0f609377d5fb41c (patch)
tree29dee223243c848d4d1099cf29f38432ac65ba18 /generic/tclInt.h
parent02563b1911feda87ad86d89bb18855a930ba178e (diff)
downloadtcl-6fa73194d556765f6a8dfe33c0f609377d5fb41c.zip
tcl-6fa73194d556765f6a8dfe33c0f609377d5fb41c.tar.gz
tcl-6fa73194d556765f6a8dfe33c0f609377d5fb41c.tar.bz2
Refactor couple more reallocations
Diffstat (limited to 'generic/tclInt.h')
-rw-r--r--generic/tclInt.h25
1 files changed, 11 insertions, 14 deletions
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 660c19f..56bef02 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -2875,21 +2875,12 @@ typedef struct ProcessGlobalValue {
*----------------------------------------------------------------------
* Common functions for growing allocations. Trivial but allows for
* experimenting with growth factors without having to change code in
- * multiple places. Usage example:
+ * multiple places. See TclAttemptOverAlloc and TclAttemptOverRealloc for
+ * usage examples. Best to use those functions if allocating in bytes.
+ * Direct use of TclUpsizeAlloc / TclResizeAlloc is needed if allocating in other
+ * units (say Tcl_UniChar), if there is a fixed size header involved or if
+ * the max limit is something other than TCL_SIZE_MAX.
*
- * allocated = TclUpsizeAlloc(oldSize, needed, TCL_SIZE_MAX);
- * while (allocated > needed) {
- * ptr = Tcl_AttemptRealloc(oldPtr, allocated);
- * if (ptr)
- * break;
- * allocated = TclUpsizeRetry(needed, allocated);
- * }
- * if (ptr == NULL) {
- * // Last resort - exact size
- * allocated = needed;
- * ptr = Tcl_Realloc(oldPtr, allocated);
- * }
- * ptr now points to an allocation of size 'allocated'
*----------------------------------------------------------------------
*/
static inline Tcl_Size
@@ -2914,6 +2905,12 @@ static inline Tcl_Size TclUpsizeRetry(Tcl_Size needed, Tcl_Size lastAttempt) {
return needed;
}
}
+MODULE_SCOPE void *TclOverAlloc(Tcl_Size needed, Tcl_Size *allocatedPtr);
+MODULE_SCOPE void *TclAttemptOverAlloc(Tcl_Size needed, Tcl_Size *allocatedPtr);
+MODULE_SCOPE void *TclOverRealloc(Tcl_Size needed, void *oldPtr,
+ Tcl_Size oldSize, Tcl_Size *allocatedPtr);
+MODULE_SCOPE void *TclAttemptOverRealloc(Tcl_Size needed, void *oldPtr,
+ Tcl_Size oldSize, Tcl_Size *allocatedPtr);
/*
*----------------------------------------------------------------