Control-C and AllocMem()

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,426
40
Albuquerque, NM
prospero.unm.edu
#1
I'm working on a plugin command which allocates memory via AllocMem(), and dumps text to stdout. Potentially a lot of memory, and a lot of text.

What happens if the user interrupts the data dump via Control-C or Control-Break? Does Take Command, in terminating the command, also have some magic way of freeing all the memory which it has allocated? Or do I need to somehow intercept Control-C and clean it up myself? (How? Would SetConsoleCtrlHandler work?)
 
#2
On Sat, 22 Jan 2011 22:38:07 -0500, you wrote:

|I'm working on a plugin command which allocates memory via AllocMem(), and dumps text to stdout. Potentially a lot of memory, and a lot of text.
|
|What happens if the user interrupts the data dump via Control-C or Control-Break? Does Take Command, in terminating the command, also have some magic way of freeing all the memory which it has allocated? Or do I need to somehow intercept Control-C and clean it up myself? (How? Would SetConsoleCtrlHandler work?)

For plugins like that, I install my own signal handler. SetConsoleCtrlHandler()
is the way to do that. Typically, I do my own clean-up and return FALSE so TCC
will handle the rest.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,426
40
Albuquerque, NM
prospero.unm.edu
#3
For plugins like that, I install my own signal handler. SetConsoleCtrlHandler() is the way to do that. Typically, I do my own clean-up and return FALSE so TCC will handle the rest.
Thanks. I figured that was probably the case. But I'd feel stupid if I went to the effort to create such a routine, only to discover that Rex is automagically cleaning up my mess for me.
 

rconn

Administrator
Staff member
May 14, 2008
10,203
86
#4
I'm working on a plugin command which allocates memory via AllocMem(), and dumps text to stdout. Potentially a lot of memory, and a lot of text.

What happens if the user interrupts the data dump via Control-C or Control-Break? Does Take Command, in terminating the command, also have some magic way of freeing all the memory which it has allocated? Or do I need to somehow intercept Control-C and clean it up myself? (How? Would SetConsoleCtrlHandler work?)
Take Command doesn't do any ^C/^Break handling; that's done in TCC.

TCC will throw an exception on a ^C / ^Break, so you can trap it with a try / catch block. TCC does not attempt to do any garbage collection on the memory (this would be very disturbing to commands like ON, DETACH, and the monitoring commands).