Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: C++ and Matlab
Date: Thu, 5 Nov 2009 14:46:03 +0000 (UTC)
Organization: Boeing
Lines: 25
Message-ID: <hcuofb$pd7$1@fred.mathworks.com>
References: <79efd49c-346d-40b2-a663-67f754b7b8da@g23g2000yqh.googlegroups.com> <ab897769-b6b9-49a5-8926-79681bcec4c1@g23g2000yqh.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257432363 26023 172.30.248.38 (5 Nov 2009 14:46:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 5 Nov 2009 14:46:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:582742


Izzy <iskandarprins@gmail.com> wrote in message <ab897769-b6b9-49a5-8926-79681bcec4c1@g23g2000yqh.googlegroups.com>...
> On Nov 4, 3:14?pm, "James Tursa"
> <aclassyguy_with_a_k_not_...@hotmail.com> wrote:
> > Izzy <iskandarpr...@gmail.com> wrote in message <79efd49c-346d-40b2-a663-67f754b7b...@g23g2000yqh.googlegroups.com>...
> > > Hi,
> >
> > > If i create a singleton object inc++code and send it into matlab and
> > > use it there, does the singleton share the same memory or are there 2
> > > singelton around, one inc++memory space and one in matlab memory
> > > space?
> >
> > Show us your code. How are you sending it to MATLAB?
> >
> > James Tursa
> 
> No code avalaible yet, since i'm just starting with this c++/matlab
> thing. Basically I have a singleton class in c++ land, which also
> needs to be used in matlab land. I was wondering if both lands share
> the same memory if i would pass the singleton into matlab and do some
> modification on the singleton, if this singleton would still be the
> same object.

In general, then, the answer is no. Your singleton could live inside the mex routine, and if you put it at the top level (outside the mexFunction) it will maintain its state across multiple mex calls. But to pass it back into the MATLAB workspace you will have to somehow turn it into an equivalent mxArray. This *copy* would be passed back into the MATLAB workspace. Changing the state of this *copy* in the MATLAB workspace will not affect the original singleton in your mex C++ routine.

James Tursa