Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Control-C and AllocMem()

Charles Dye

Super Moderator
May
4,971
128
Staff member
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?)
 
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.
 
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.
 
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).
 
Back
Top