From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: mexCallMATLAB crashes in loops?
Date: Thu, 3 Jan 2013 08:23:10 +0000 (UTC)
Organization: Boeing Co
Lines: 19
Message-ID: <kc3f5e$945$>
References: <kbt4p3$n00$> <kbu49s$3g8$> <kbv5ko$it4$> <kc27ra$sau$> <kc2cor$he8$> <kc2g3l$sb4$> <kc3aot$ogg$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1357201390 9349 (3 Jan 2013 08:23:10 GMT)
NNTP-Posting-Date: Thu, 3 Jan 2013 08:23:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: comp.soft-sys.matlab:785844

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kc3aot$ogg$>...
> "James Tursa" wrote in message <kc2g3l$sb4$>...
> > "Yi " <> wrote in message 
> > 
> > I should further add that if you are going to be working with large variables, there are better functions to use for getting read-only copies of stuff into struct or cell elements ... they are the undocumented functions mxCreateSharedDataCopy and mxCreateReference. 
> James, can you please post a calling syntax of mxCreateSharedDataCopy and mxCreateReference ? Thanks.
> Bruno

mxArray *mxCreateSharedDataCopy(mxArray *mx);

Returns a pointer to a shared data copy of the input mx.  The resulting mxArray will be of type TEMPORARY (4) (i.e., on the garbage collection list).

mxArray *mxCreateReference(mxArray *mx);

Returns the value mx after bumping up the reference count of mx by 1. The intent is to use this function on a variable that is already a sub-element (i.e., part of a struct or cell array) and immediately place the result into another struct field or cell array element so that it gets destroyed the appropriate number of times when variables get cleared. I.e., the first time it gets destroyed the reference count simply gets bumped down by 1 (nothing actually gets destroyed). The last time it gets destroyed (after the reference count has been bumped down to 0) the header and data areas are actually destroyed (freed).

James Tursa