Version 7 of Tcl_Alloc

Updated 2022-10-26 05:24:54 by agast

Allocate memory using the Tcl library's memory allocation engine. Like malloc, but integrates with the memory command (if that's defined). Pairs up with Tcl_Realloc and Tcl_Free.

Tcl_Alloc and Tcl_Realloc guarantee to always return a valid block of memory; they will panic (call Tcl_Panic) if memory allocation fails. For alternatives that return NULL, use Tcl_AttemptAlloc and Tcl_AttemptRealloc.

See also the manual .

(Note: the manual does not mention Tcl_Panic)

(2022-10-25 from <aku> in the #tcl chat): Tcl_Obj are allocated in thread-local memory pools, and are thus (implicitly) owned by the thread allocating it. Releasing it in a different thread should break things. Because the pool is thread-local access is not mutex protected, there is the expectation that no other thread accesses it, and your Tcl_DecrRefCount from the other thread violates this assumption.

In other words: don't Tcl_Alloc/ckalloc something in one thread to release it in another thread.