Am 02.02.2006 um 21:21 schrieb Gustaf Neumann:

how comes, that ckalloc is so much faster?

It avoids the malloc's lock and builds its own
malloc tables per-thread. So when lots of threads
start to attack the malloc, there is quite a lot
of contention on the mutex, so they go sleep for
a while.

how do malloc/ckmalloc relate to ns_malloc?

malloc is the bottom layer as provides with the OS
(or the malloc library).

ckalloc is a macro defined in Tcl so you can declare
TCL_MEM_DEBUG and it will add some additional layer
so the Tcl memory debugging tools can be used.
If no TCL_MEM_DEBUG is declared, it defaults to Tcl_Alloc.
The Tcl_Alloc is different for non-thread and thread-builds.
This is controlled by USE_THREAD_ALLOC when compiling the
Tcl library and is default for threaded builds. This activates
special MT-optimized allocator. It handles all memory allocations
<16284 bytes in per-thread tables, instead of shared tables
thus avioding lock contention. This is what AS used before and it
got into Tcl as it was/is pretty efficient overall. This is not
always the case for 1cpu boxes, as I've seen in my tests.

ns_malloc is just a wrapper arround the ckalloc.

Cheers
Zoran

Reply via email to