<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264969</link>
    <title>MATLAB Central Newsreader - C++ and Matlab</title>
    <description>Feed for thread: C++ and Matlab</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 04 Nov 2009 14:07:48 -0500</pubDate>
      <title>C++ and Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264969#692041</link>
      <author>Izzy</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
If i create a singleton object in c++ code and send it into matlab and&lt;br&gt;
use it there, does the singleton share the same memory or are there 2&lt;br&gt;
singelton around, one in c++ memory space and one in matlab memory&lt;br&gt;
space?&lt;br&gt;
&lt;br&gt;
Thanks</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 14:14:02 -0500</pubDate>
      <title>Re: C++ and Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264969#692044</link>
      <author>Sebastiaan </author>
      <description>Izzy &amp;lt;iskandarprins@gmail.com&amp;gt; wrote in message &amp;lt;79efd49c-346d-40b2-a663-67f754b7b8da@g23g2000yqh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If i create a singleton object in c++ code and send it into matlab and&lt;br&gt;
&amp;gt; use it there, does the singleton share the same memory or are there 2&lt;br&gt;
&amp;gt; singelton around, one in c++ memory space and one in matlab memory&lt;br&gt;
&amp;gt; space?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
I am not sure if I fully understand...&lt;br&gt;
&lt;br&gt;
If you have a C++ subroutine which is called by Matlab, you share the memory (if you use it well: Matlab will give your C++ routine a pointer).&lt;br&gt;
&lt;br&gt;
I am not sure how it works if you are calling Matlab from a C++ program...&lt;br&gt;
&lt;br&gt;
Sebastiaan</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 14:14:02 -0500</pubDate>
      <title>Re: C++ and Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264969#692045</link>
      <author>James Tursa</author>
      <description>Izzy &amp;lt;iskandarprins@gmail.com&amp;gt; wrote in message &amp;lt;79efd49c-346d-40b2-a663-67f754b7b8da@g23g2000yqh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If i create a singleton object in c++ code and send it into matlab and&lt;br&gt;
&amp;gt; use it there, does the singleton share the same memory or are there 2&lt;br&gt;
&amp;gt; singelton around, one in c++ memory space and one in matlab memory&lt;br&gt;
&amp;gt; space?&lt;br&gt;
&lt;br&gt;
Show us your code. How are you sending it to MATLAB?&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
    <item>
      <pubDate>Thu, 05 Nov 2009 12:55:45 -0500</pubDate>
      <title>Re: C++ and Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264969#692373</link>
      <author>Izzy</author>
      <description>On Nov 4, 3:14&#160;pm, &quot;James Tursa&quot;&lt;br&gt;
&amp;lt;aclassyguy_with_a_k_not_...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Izzy &amp;lt;iskandarpr...@gmail.com&amp;gt; wrote in message &amp;lt;79efd49c-346d-40b2-a663-67f754b7b...@g23g2000yqh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; If i create a singleton object inc++code and send it into matlab and&lt;br&gt;
&amp;gt; &amp;gt; use it there, does the singleton share the same memory or are there 2&lt;br&gt;
&amp;gt; &amp;gt; singelton around, one inc++memory space and one in matlab memory&lt;br&gt;
&amp;gt; &amp;gt; space?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Show us your code. How are you sending it to MATLAB?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; James Tursa&lt;br&gt;
&lt;br&gt;
No code avalaible yet, since i'm just starting with this c++/matlab&lt;br&gt;
thing. Basically I have a singleton class in c++ land, which also&lt;br&gt;
needs to be used in matlab land. I was wondering if both lands share&lt;br&gt;
the same memory if i would pass the singleton into matlab and do some&lt;br&gt;
modification on the singleton, if this singleton would still be the&lt;br&gt;
same object.</description>
    </item>
    <item>
      <pubDate>Thu, 05 Nov 2009 14:18:03 -0500</pubDate>
      <title>Re: C++ and Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264969#692391</link>
      <author>Rune Allnor</author>
      <description>On 5 Nov, 13:55, Izzy &amp;lt;iskandarpr...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; On Nov 4, 3:14&#160;pm, &quot;James Tursa&quot;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;lt;aclassyguy_with_a_k_not_...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; Izzy &amp;lt;iskandarpr...@gmail.com&amp;gt; wrote in message &amp;lt;79efd49c-346d-40b2-a663-67f754b7b...@g23g2000yqh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; If i create a singleton object inc++code and send it into matlab and&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; use it there, does the singleton share the same memory or are there 2&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; singelton around, one inc++memory space and one in matlab memory&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; space?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Show us your code. How are you sending it to MATLAB?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; James Tursa&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; No code avalaible yet, since i'm just starting with this c++/matlab&lt;br&gt;
&amp;gt; thing. Basically I have a singleton class in c++ land, which also&lt;br&gt;
&amp;gt; needs to be used in matlab land. I was wondering if both lands share&lt;br&gt;
&amp;gt; the same memory if i would pass the singleton into matlab and do some&lt;br&gt;
&amp;gt; modification on the singleton, if this singleton would still be the&lt;br&gt;
&amp;gt; same object.&lt;br&gt;
&lt;br&gt;
How are you proposing to do this?&lt;br&gt;
&lt;br&gt;
You can make C++ and matlab interact in two ways:&lt;br&gt;
&lt;br&gt;
1) Call C++ from matlab in the form of MEXfiles&lt;br&gt;
2) Call the matlab engine from a C++ executable&lt;br&gt;
&lt;br&gt;
In case 1 your C++ singleton will have to be declared and&lt;br&gt;
initialized somewhere near the entry point of your C++&lt;br&gt;
MEX routine, and be available to your C++ code. However,&lt;br&gt;
its scope - and thus lifetime - will end near the return&lt;br&gt;
point of your MEX routine. So there is no reason to expect&lt;br&gt;
the singleton to be available from matlab scope, or to&lt;br&gt;
stay available between multiple calls to the MEX routine.&lt;br&gt;
&lt;br&gt;
In case 2 you would ideally want to pass the singleton&lt;br&gt;
from C++ into matlab scope, to become accessible to matlab.&lt;br&gt;
That can not be done. The best you can do is to pass variables&lt;br&gt;
from the singleton through the engine gateway, and read&lt;br&gt;
modified data back.&lt;br&gt;
&lt;br&gt;
Rune</description>
    </item>
    <item>
      <pubDate>Thu, 05 Nov 2009 14:46:03 -0500</pubDate>
      <title>Re: C++ and Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264969#692411</link>
      <author>James Tursa</author>
      <description>Izzy &amp;lt;iskandarprins@gmail.com&amp;gt; wrote in message &amp;lt;ab897769-b6b9-49a5-8926-79681bcec4c1@g23g2000yqh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On Nov 4, 3:14?pm, &quot;James Tursa&quot;&lt;br&gt;
&amp;gt; &amp;lt;aclassyguy_with_a_k_not_...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; Izzy &amp;lt;iskandarpr...@gmail.com&amp;gt; wrote in message &amp;lt;79efd49c-346d-40b2-a663-67f754b7b...@g23g2000yqh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; If i create a singleton object inc++code and send it into matlab and&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; use it there, does the singleton share the same memory or are there 2&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; singelton around, one inc++memory space and one in matlab memory&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; space?&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Show us your code. How are you sending it to MATLAB?&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; James Tursa&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; No code avalaible yet, since i'm just starting with this c++/matlab&lt;br&gt;
&amp;gt; thing. Basically I have a singleton class in c++ land, which also&lt;br&gt;
&amp;gt; needs to be used in matlab land. I was wondering if both lands share&lt;br&gt;
&amp;gt; the same memory if i would pass the singleton into matlab and do some&lt;br&gt;
&amp;gt; modification on the singleton, if this singleton would still be the&lt;br&gt;
&amp;gt; same object.&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
    <item>
      <pubDate>Fri, 06 Nov 2009 08:22:46 -0500</pubDate>
      <title>Re: C++ and Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264969#692618</link>
      <author>Izzy</author>
      <description>On Nov 5, 3:46&#160;pm, &quot;James Tursa&quot;&lt;br&gt;
&amp;lt;aclassyguy_with_a_k_not_...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Izzy &amp;lt;iskandarpr...@gmail.com&amp;gt; wrote in message &amp;lt;ab897769-b6b9-49a5-8926-79681bcec...@g23g2000yqh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; On Nov 4, 3:14?pm, &quot;James Tursa&quot;&lt;br&gt;
&amp;gt; &amp;gt; &amp;lt;aclassyguy_with_a_k_not_...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Izzy &amp;lt;iskandarpr...@gmail.com&amp;gt; wrote in message &amp;lt;79efd49c-346d-40b2-a663-67f754b7b...@g23g2000yqh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; If i create a singleton object inc++code and send it into matlab and&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; use it there, does the singleton share the same memory or are there 2&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; singelton around, one inc++memory space and one in matlab memory&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; space?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Show us your code. How are you sending it to MATLAB?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; James Tursa&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; No code avalaible yet, since i'm just starting with thisc++/matlab&lt;br&gt;
&amp;gt; &amp;gt; thing. Basically I have a singleton class inc++land, which also&lt;br&gt;
&amp;gt; &amp;gt; needs to be used in matlab land. I was wondering if both lands share&lt;br&gt;
&amp;gt; &amp;gt; the same memory if i would pass the singleton into matlab and do some&lt;br&gt;
&amp;gt; &amp;gt; modification on the singleton, if this singleton would still be the&lt;br&gt;
&amp;gt; &amp;gt; same object.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; 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 mexC++routine.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; James Tursa- Hide quoted text -&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; - Show quoted text -&lt;br&gt;
&lt;br&gt;
Aha, thanks. So basically whenever I send in data to and from matlab a&lt;br&gt;
copy is made thus is invalidates the usage of a singleton.</description>
    </item>
    <item>
      <pubDate>Fri, 06 Nov 2009 16:14:02 -0500</pubDate>
      <title>Re: C++ and Matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264969#692716</link>
      <author>James Tursa</author>
      <description>Izzy &amp;lt;iskandarprins@gmail.com&amp;gt; wrote in message &amp;lt;7fa345d3-dbfa-4afd-b79d-4ffe72c6192c@g23g2000yqh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Aha, thanks. So basically whenever I send in data to and from matlab a&lt;br&gt;
&amp;gt; copy is made thus is invalidates the usage of a singleton.&lt;br&gt;
&lt;br&gt;
From a practical standpoint, yes. From a technical standpoint, you *could* create your singleton using mxMalloc etc memory allocation functions and make that memory part of an mxArray that was returned to MATLAB. MATLAB will not actually copy the data area of the variable you return. But once you *change* the data area on the MATLAB side MATLAB will create a new data area for the changed results and break the connection between the MATLAB variable and your singleton. So it amounts to the same thing. &lt;br&gt;
&lt;br&gt;
To get the functionality of your singleton on the MATLAB side you would have to resort to calling the mex file for data access and data setting. I.e., have your singleton at the top level so it maintains its state across multiple mex calls. Then when you want the value, call the mex routine with a special input (e.g., a string 'get') that will cause the mex function to return a copy of the singleton as an mxArray. If you want to change the state of the singleton, then create the changed state on the MATLAB side and call the mex routine with this new state and another special input (e.g., a string 'set') that sets the singleton value. Not a real clean solution, but you could get it to work.&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
  </channel>
</rss>

