Jump to content

Transaction Data Pointer

Recommended Posts

What is the correct way to handle transaction data pointer (set_data_ptr).
If I free it right after b_transport I get an error since transaction handling isn't completes.
Unlike tlm_extension it is not freed once transaction is completed.

void rx_thread() {

    uint8_t *buf = new uint8_t[ETH_MAC_PACKET_MAX_LEN];

    tlm::tlm_generic_payload* pkt_trans = new tlm::tlm_generic_payload();
    pkt_trans->set_data_ptr((unsigned char *)(buf));
    phy2mac->b_transport(*pkt_trans, delay);

    // Note:not calling "delete [] buf;" here since this data is a part of generic payload now and
    //       shouldn't be destroyed until transaction handling completes! Although b_transport() is
    //       a synchronous call indeed, queue is filled with pointers to original structures rather then to their clones.



Link to comment
Share on other sites


Normally the initiator is considered as owner of the payload, i.e. he should take care of allocating and de-allocating it.

The target should decide how to use the data. If the target wants to keep it/store it, the target should make a copy of the data. In that sense, the transaction is completed when b_transport returns because the initiator transfered it to the target and the target had a chance to handle it.

A benefit of this is that you do not need dynamic allocation of the buffer buf.




Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...