Jump to content

Recommended Posts

Posted

Dear all, 

to define extensions of the generic payload, I defined also a memory manager class, implementing the tlm_mm_interface. 
I googled and tried almost all implementations available out there - they all generate memory leaks (as bad as 80 bytes
in 2 blocks, according to Valgrind). Can anybody help me?

The issue seems to be caused by the allocate method. 

Header file: 

class mem_manager : public tlm::tlm_mm_interface{
  
  public:
    std::vector<tlm::tlm_generic_payload *> free_list;
    tlm::tlm_generic_payload * allocate(); 
    void free(tlm::tlm_generic_payload *);

    tlm::tlm_generic_payload * ptr;
private:

    ~mem_manager();
};

Implementation: 

mem_manager::~mem_manager(){
}

tlm::tlm_generic_payload * mem_manager::allocate(){

     if (!free_list.empty()) {
       ptr = free_list.back();
       free_list.pop_back();
       
       cout<<"free list not empty"<<endl; 
     } 
     else {
       ptr = new tlm::tlm_generic_payload(this);
       cout<<"free list empty"<<endl; 
     }
     return ptr;
}    
 
void mem_manager::free(tlm::tlm_generic_payload * trans){
    free_list.push_back((tlm::tlm_generic_payload *)trans);
}

Example of code using the memory manager: 


  tlm::tlm_generic_payload * trans; 	
  sc_time time;  
  
  mem = new mem_manager(); 
  trans = mem->allocate(); 
  payload_data = new reg_extension; 
  
  payload_data->value = sc_bv<16>("01"); 
  payload_data->reset = 1; 

  trans->set_data_length(sizeof(register_data_t)); 
  trans->set_auto_extension(payload_data); 

  trans->set_address(0); 
  trans->set_write(); 

  initiator_socket->b_transport(*trans, time); 

  if(trans->is_response_ok()){
  }
  else{
  cout<<"Error!"<<endl;
  }

Regards, 
S. 

Posted

Hello,

Would it be possible for you to share the bare minimum code files for the project, which reproduces this behaviour?(e.g.: Github/Gist etc.)

Regards,

Ameya Vikram Singh

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.

Guest
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...