4

I'm writing a module in SystemC where within the constructor I have a variable initialized with new:

SC_CTOR(MY_MODULE)
{
    ...
    ...
    my_matrix = new unsigned char [a*b];
    ...
    ...
}

How can I declare the destructor to release the memory when the simulation ends?

Marco
  • 391
  • 4
  • 18

1 Answers1

6

You need to use the C++ semantic. There is no equivalent of SC_CTOR for the destructor.

SC_MODULE(MyModule)
{
    SC_CTOR(MyModule)
    {
        my_matrix = new unsigned char [10];
    }

    ~MyModule() {
        delete my_matrix;
    }

private:
    unsigned char * my_matrix;
};
Guillaume
  • 1,277
  • 8
  • 11