5.0

5.0 | 2 ratings Rate this file 8 Downloads (last 30 days) File Size: 2.84 KB File ID: #24349

Use C++ "new" and "delete" in MATLAB MEX files

by Petter

 

05 Jun 2009

This code modífies "new" and "delete" to register all allocated memory with the memory manager.

| Watch this File

File Information
Description

This code enables you to use the "new" and "delete" keywords in C++ to allocate and deallocate your memory. This enables you to create objects with constructors dynamically.

Normally, using new and delete in MEX files might leak memory if the user presses Ctrl+C or the MEX file terminates with an error. This code modífies "new" and "delete" to register all allocated memory with MATLAB's memory manager.

No modifications to existing C++ code is required.

MATLAB release MATLAB 7.5 (R2007b)
Other requirements C++ compiler
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
23 Feb 2011 Tim

I think you're missing some: return ptr;

03 Jul 2011 Hawren

tested. it is working

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
c Petter 05 Jun 2009 11:16:44
new Petter 05 Jun 2009 11:16:44
delete Petter 05 Jun 2009 11:16:44
memory Petter 05 Jun 2009 11:16:44
memory management Petter 05 Jun 2009 11:16:44
c Chen 03 Mar 2011 09:39:52
delete Chen 03 Mar 2011 09:39:56
memory Chen 03 Mar 2011 09:39:58

Contact us at files@mathworks.com