Jump to content

Recommended Posts

I read some source code.

class TlmExtension : public tlm_extension<TlmExtension>
{
  ...
};
void setExtension(tlm::tlm_generic_payload &in, tlm::tlm_generic_payload &out)
{
    TlmExtension *input  = (TlmExtension *)0;
    TlmExtension *output = new TlmExtension;
    in.get_extension(input);
    if (input != NULL) {
        output->setNum(input->getNum());
        output->setChannel(input->getChannel());
        out.set_extension(output);
    }
}

 

I think above code is wrong. Because of when exit  setExtension  function. We cant delete object create by new operator (output )

How to resolve this problem?  Thanks.

BR.

 

Share this post


Link to post
Share on other sites

Actually this is done in the desrtuctor of the tlm_generic_payload. This part calls for all extensions the free() function. So if out is handled properly destroyed all extensions are destroyed as well. The other option is to call free_all_extensions() explicitly which also calls free() for all extensions as well as for auto extensions (those might be registered when a memory manager for the generic payload is used, usually in AT style modelling using the non-blocking interfaces).

HTH

Share this post


Link to post
Share on other sites

Thank @Eyck

As your comment, my understand that

1. It is done in the destructor of the the tlm_generic_payload ( both AT and LT style )

2. The other option is to call free_all_extensions() after transaction completed ( only AT style )

Is it correct? Thanks.

Share this post


Link to post
Share on other sites

In principle yes, but I would not call it LT or AT as it depends on hte use of a memory manager which can be used in any case.

Cheers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×