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

Control-C and AllocMem()

Discussion in 'Plugins' started by Charles Dye, Jan 22, 2011.

  1. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    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.
     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    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.
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,804
    Likes Received:
    82
    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).
     
  5. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    Okay; thanks.
     

Share This Page