Code covered by the BSD License  

Highlights from
mxGetPropertyPtr C-mex function

4.33333

4.3 | 3 ratings Rate this file 12 Downloads (last 30 days) File Size: 45.1 KB File ID: #30672

mxGetPropertyPtr C-mex function

by

 

Fast memory efficient alternative to the API function mxGetProperty.

| Watch this File

File Information
Description

When The Mathworks® introduced MATLAB® version R2008a they included a new object oriented format called classdef. This addition greatly expanded the object oriented capabilities of MATLAB® at the m-file level. There were also two new mex API functions introduced at that same time: mxGetProperty and mxSetProperty. Unfortunately, both of these functions work with copies of the properties and not the actual properties themselves. So whereas the old-style class variables can easily and efficiently be accessed with the mex API functions mxGetField, mxGetFieldByNumber, mxSetField, and mxSetFieldByNumber since they use pointers to the original properties, there were no equivalent mex API functions provided for the newer classdef classes. This presents a problem for the mex programmer, particularly if the properties in question are large. Using mxGetProperty will significantly slow the routine down and also risk using up valuable heap memory. The same is true for mxSetProperty.

The new mxGetPropertyPtr C-mex function provided in this package solves half of the problem. It returns a pointer to the original property rather than a pointer to a copy of the property. Thus the property can be accessed efficiently inside a mex routine. The other half of the problem, providing an efficient replacement for mxSetProperty, is in work and will likely be included with the next release of this package.

MATLAB release MATLAB 7.6 (R2008a)
Other requirements Any C/C++ compiler, such as the lcc compiler shipped with MATLAB.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
28 Aug 2014 Ilan Bar

Works great for Windows. Is there a solution for LINUX as well?

24 Nov 2011 Etienne Balmes

Excellent and very interesting on the way MATLAB handles transmission of handles. I have found the auto-test difficult to use since the "memory" function of matlab does not exist on linux and the testing done in this submission is done within a mex file.

05 Apr 2011 Pavel Holoborodko  

Contact us