mathworks / libmexclass

libmexclass is a MATLAB framework which enables users to implement the functionality of MATLAB classes in terms of equivalent C++ classes using MEX.
BSD 3-Clause "New" or "Revised" License
5 stars 1 forks source link

Closes #70: Recycle proxy ids after they are unmanaged #71

Closed sgilmore10 closed 11 months ago

sgilmore10 commented 11 months ago

Rationale

libmexclass should keep a list of "unmanaged" proxy IDs that can be reused. Currently, once a proxy ID is handed out, it cannot be reused even if the object associated with the ID has been deleted.

Change

  1. Added a new member variable called recycled_ids to ProxyManager. recycled_ids is a std::deque<ID>
  2. ProxyManager::unmanageProxy(ID) pushes the unmanaged proxy ID to the back of recycled_ids.
  3. ProxyManager::manageProxy(proxy) checks if recycled_ids is not empty. If so, it pops the first ID from recycled_ids and uses it as the ID for the newly managed proxy. Otherwise, it uses current_proxy_id as the new ID and increments current_proxy_id by one.

Testing

Manually verified that libmexclass reuses proxy IDs if they are available. Otherwise, it creates new proxy IDs.

kevingurney commented 11 months ago

+1