Path: news.mathworks.com!not-for-mail
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$1@newscl01ah.mathworks.com>
References: <kbt4p3$n00$1@newscl01ah.mathworks.com> <kbu49s$3g8$1@newscl01ah.mathworks.com> <kbv5ko$it4$1@newscl01ah.mathworks.com> <kc27ra$sau$1@newscl01ah.mathworks.com> <kc2cor$he8$1@newscl01ah.mathworks.com> <kc2g3l$sb4$1@newscl01ah.mathworks.com> <kc3aot$ogg$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1357201390 9349 172.30.248.45 (3 Jan 2013 08:23:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 3 Jan 2013 08:23:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:785844

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kc3aot$ogg$1@newscl01ah.mathworks.com>...
> "James Tursa" wrote in message <kc2g3l$sb4$1@newscl01ah.mathworks.com>...
> > "Yi " <dora.zhuyi@gmail.com> 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