Tcl Source Code

View Ticket
Login
Ticket UUID: 1abbfcdff166b9f6bd2de2c27e5d09315f7baaa0
Title: Information request regarding 'memory' command
Type: Support Version: 8.4.9.1
Submitter: sakthivp Created on: 2014-03-06 10:13:48
Subsystem: 41. Memory Allocation Assigned To: nobody
Priority: 6 Severity: Minor
Status: Open Last Modified: 2014-03-07 07:35:47
Resolution: None Closed By: nobody
    Closed on:
Description:
I want to use the command 'memory' to see the memory allocations in Tcl interpreter. To achieve this, i have called the function Tcl_InitMemory() once after creating the Tcl interpreter with the interpreter handle as an argument(created using Tcl_CreateInterp() function). 
Will this suffice, to avail the memory command on an Interpreter ? or should i implement anything else ?
Please help me with the required information.
User Comments: sakthivp added on 2014-03-07 07:35:47:
I compiled the Tcl libraries with TCL_MEM_DEBUG symbol by configuring using below command.

./configure --prefix=/scratch/sakthi/Tcl_8.4.9_debug --enable-symbols=all

I found a library with name libtcl8.4g.so. Then i wrote a C program which uses the debug shared object to invoke Tcl 'memory' command. The program failed to execute the 'memory' command.
C program
---------
#include <stdio.h>
#include <tcl.h>
#include <stdio.h>
#include <tcl.h>
int main()
{
 int x=0;
 Tcl_Interp* a;
 a =  Tcl_CreateInterp();
 Tcl_Init(a);
 Tcl_InitMemory(a);
 if (a == NULL)
 printf("Interpreter creation Failed \n");
 x = Tcl_Eval(a,(char *)"memory info");
 Tcl_DeleteInterp(a);
 printf("DeleteInterpreter x=%d \n",x);
}
---------------------
Compilation flags on solaris10 server

/opt/Studio11/SUNWspro/bin/CC -L/scratch/sakthi/Tcl_8.4.9_debug/lib -ltcl8.4g -I/scratch/sakthi/Tcl_8.4.9_debug/include  Tcl_inter_problem.c -o Tcl_inter_problem
----------------------
Output of the program

DeleteInterpreter x=1  // Tcl_Eval function returns 1 (TCL_ERROR), unable to execute memory command.

Am i doing anything wrong?

I have attached the Makefile which was generated by configure script.

sakthivp added on 2014-03-07 05:25:36:
Thank yous so much for your answer. I will try the same with my program.

dkf added on 2014-03-06 13:54:38:

For reference, the definition of Tcl_InitMemory in mem-debug mode is this:

void
Tcl_InitMemory(
    Tcl_Interp *interp)         /* Interpreter in which commands should be
                                 * added */
{
    TclInitDbCkalloc();
    Tcl_CreateCommand(interp, "memory", MemoryCmd, NULL, NULL);
    Tcl_CreateCommand(interp, "checkmem", CheckmemCmd, NULL, NULL);
}
Some of those functions mentioned are not exposed outside the Tcl library, and others are in the internal interfaces (which you're encouraged to ignore, and which are principally undocumented).


dkf added on 2014-03-06 13:51:28:

The whole Tcl library must be compiled with TCL_MEM_DEBUG defined, in order for the tracking hooks to be put in the memory management code at all. It's also recommended that you recompile your code with that symbol defined when using the Tcl library (so allocations via Tcl's APIs from your code also get tracked), though it shouldn't strictly be necessary.

The supported way of doing this is by passing --enable-symbols=mem to configure when building Tcl. (This implies --enable-symbols, and is implied by --enable-symbols=all, which turns on other types of debugging as well.)

This is in addition to calling Tcl_InitMemory. When TCL_MEM_DEBUG is not defined when building Tcl, Tcl_InitMemory is an empty function, a no-op.


Attachments: