Control-C and AllocMem()

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,223
78
Albuquerque, NM
prospero.unm.edu
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?)
 
May 20, 2008
10,637
82
Syracuse, NY, USA
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
4,223
78
Albuquerque, NM
prospero.unm.edu
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
11,931
133
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).
 
Thread starter Similar threads Forum Replies Date
V Plugins 1
V Plugins 4