Tcl_DumpActiveMemory(3tcl)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– Tcl_DumpActiveMemory β€” the validated memory allocation interface, bestie πŸ’–

okay so this is a Tcl Library Procedures page, and it's about three little functions that let you peek inside Tcl's memory-debugging brain: Tcl_DumpActiveMemory, Tcl_InitMemory, and Tcl_ValidateAllMemory. Together they're the validated memory allocation interface. grab a snack, we're going in πŸ“


✨ SYNOPSIS ✨

#include <tcl.h>

int
Tcl_DumpActiveMemory(fileName)

Tcl_InitMemory(interp)

Tcl_ValidateAllMemory(fileName, line)

πŸŽ€ ARGUMENTS πŸŽ€

  • Tcl_Interp *interp (in) β€” the Tcl interpreter you want to add commands to. that's it, that's the vibe.
  • const char *fileName (in) β€” for Tcl_DumpActiveMemory, this is the name of the file that memory info gets written to. for Tcl_ValidateAllMemory, it's the name of the file the call is coming from (normally __FILE__). same name, two whole jobs, multitasking icon πŸ’…
  • int line (in) β€” the line number where the Tcl_ValidateAllMemory call happens (normally __LINE__).

πŸ’œ DESCRIPTION πŸ’œ

so these functions give you access to Tcl memory debugging info. major caveat incoming: they only actually do anything when Tcl has been compiled with TCL_MEM_DEBUG defined at compile-time. when TCL_MEM_DEBUG is not defined, all of these functions are no-ops. literally just vibing and doing nothing. no cap.

Tcl_DumpActiveMemory outputs a list of all currently allocated memory to the specified file. for each allocated block of memory, the info it spits out is:

  • starting and ending addresses (excluding the guard zone, okay bestie, not the guard zone)
  • size
  • the source file where Tcl_Alloc was called to allocate that block
  • the line number in that file

it's especially useful to call Tcl_DumpActiveMemory after the Tcl interpreter has been deleted. like, that's the moment. that's when the tea gets spilled πŸ«–βœ¨

Tcl_InitMemory adds the Tcl memory command to the interpreter given by interp. and fun fact: Tcl_InitMemory is called by Tcl_Main. so it's already out here living its life in the wild.

Tcl_ValidateAllMemory forces a validation of the guard zones of all currently allocated blocks of memory. normally, validation of a block happens when it's freed β€” unless full validation is enabled, in which case validation of all blocks happens when Tcl_Alloc and Tcl_Free are called. this function forces that validation to occur at any point you want. you're the main character, you pick the moment πŸ‘‘


🌈 SEE ALSO 🌈

  • TCL_MEM_DEBUG
  • memory

πŸ¦‹ KEYWORDS πŸ¦‹

memory, debug


and that's the whole page, bestie πŸ’– this one's from the Tcl crew, version 8.1 β€” the Tcl_DumpActiveMemory(3tcl) girlies stay validated, stay allocated, and stay free of guard-zone shenanigans. mwah πŸŽ€πŸ’…βœ¨

πŸ“¦ where this page comes from