<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Matlab&#039;s internal memory representation	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlabs-internal-memory-representation</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Sun, 29 Apr 2018 05:14:10 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Cris Luengo		</title>
		<link>https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-424325</link>

		<dc:creator><![CDATA[Cris Luengo]]></dc:creator>
		<pubDate>Sun, 29 Apr 2018 05:14:10 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2798#comment-424325</guid>

					<description><![CDATA[Finding the size of the mxArray header is much simpler than what is shown here:

&lt;pre lang=&quot;matlab&gt;
&gt;&gt; S = cell(2);
&gt;&gt; whos
  Name      Size            Bytes  Class    Attributes
  S         2x2                32  cell               

&gt;&gt; S{1} = [];
&gt;&gt; whos
  Name      Size            Bytes  Class    Attributes
  S         2x2               136  cell               

&gt;&gt; 136-32
ans =
   104
&lt;/pre&gt;

Still 104 bytes in the header for MATLAB R2017a.]]></description>
			<content:encoded><![CDATA[<p>Finding the size of the mxArray header is much simpler than what is shown here:</p>
<pre lang="matlab>
>> S = cell(2);
>> whos
  Name      Size            Bytes  Class    Attributes
  S         2x2                32  cell               

>> S{1} = [];
>> whos
  Name      Size            Bytes  Class    Attributes
  S         2x2               136  cell               

>> 136-32
ans =
   104
</pre>
<p>Still 104 bytes in the header for MATLAB R2017a.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ofek Shilon		</title>
		<link>https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-405503</link>

		<dc:creator><![CDATA[Ofek Shilon]]></dc:creator>
		<pubDate>Thu, 27 Apr 2017 13:29:21 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2798#comment-405503</guid>

					<description><![CDATA[Starting the reversing work from the address returned by mxGetData caused some of the interesting mxArray fields to be missed (eg classID). I recently uploaded a &lt;a href=&quot;https://github.com/OfekShilon/mxArrayWatch/blob/master/README.md&quot; rel=&quot;nofollow&quot;&gt;similar work of mine to github&lt;/a&gt;, hopefully it adds value to anyone trying to watch mxArray&#039;s (at least from visual studio).]]></description>
			<content:encoded><![CDATA[<p>Starting the reversing work from the address returned by mxGetData caused some of the interesting mxArray fields to be missed (eg classID). I recently uploaded a <a href="https://github.com/OfekShilon/mxArrayWatch/blob/master/README.md" rel="nofollow">similar work of mine to github</a>, hopefully it adds value to anyone trying to watch mxArray&#8217;s (at least from visual studio).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Undocumented Matlab MEX API &#124; Undocumented Matlab		</title>
		<link>https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-229144</link>

		<dc:creator><![CDATA[Undocumented Matlab MEX API &#124; Undocumented Matlab]]></dc:creator>
		<pubDate>Wed, 24 Jul 2013 18:02:30 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2798#comment-229144</guid>

					<description><![CDATA[[...] it is possible to see high level C++ classes MathWorks developers use for work. Peter Li has posted an article about mxArray_tag&#8216;s evolution and internal structure in 2012. [...]]]></description>
			<content:encoded><![CDATA[<p>[&#8230;] it is possible to see high level C++ classes MathWorks developers use for work. Peter Li has posted an article about mxArray_tag&#8216;s evolution and internal structure in 2012. [&#8230;]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Christian Di		</title>
		<link>https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-207363</link>

		<dc:creator><![CDATA[Christian Di]]></dc:creator>
		<pubDate>Wed, 29 May 2013 20:40:17 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2798#comment-207363</guid>

					<description><![CDATA[Dear Mr. Altman,
First of all, I wish to congratulate you for the excellent work done with this &quot;Undocumented Matlab&quot; portal. There are lots of things actually undocumented in Matlab and that need to be clarified. Currenlty, I am an engineer student that is working with coders (H.264-HDTV) and therefore working at the bit level with Matlab. Bit level operations and specially algorithms that demand to consider byte alignments are quiet difficult in order to improve speed. While reading this article I was animated to consider to &quot;break&quot; Matlab&#039;s FILE structure. Matlab has an option in the fread function to consider bit reding called &quot;ubit&quot;. This property is not seen in C, nor C++, nor in Octave. I wanted to ask all the persons involved in this blog if you believe that there is a special pointer &quot;hidden&quot; in Matlab&#039;s &quot;fread&quot; structure in order to save the bit position. This is a topic that I been trying to discover in the last months and where I was not able to find information. If you could know something about this, I will appreciate your help.

Once more, congratulations for the great work done.

Best regards,

Christian Di]]></description>
			<content:encoded><![CDATA[<p>Dear Mr. Altman,<br />
First of all, I wish to congratulate you for the excellent work done with this &#8220;Undocumented Matlab&#8221; portal. There are lots of things actually undocumented in Matlab and that need to be clarified. Currenlty, I am an engineer student that is working with coders (H.264-HDTV) and therefore working at the bit level with Matlab. Bit level operations and specially algorithms that demand to consider byte alignments are quiet difficult in order to improve speed. While reading this article I was animated to consider to &#8220;break&#8221; Matlab&#8217;s FILE structure. Matlab has an option in the fread function to consider bit reding called &#8220;ubit&#8221;. This property is not seen in C, nor C++, nor in Octave. I wanted to ask all the persons involved in this blog if you believe that there is a special pointer &#8220;hidden&#8221; in Matlab&#8217;s &#8220;fread&#8221; structure in order to save the bit position. This is a topic that I been trying to discover in the last months and where I was not able to find information. If you could know something about this, I will appreciate your help.</p>
<p>Once more, congratulations for the great work done.</p>
<p>Best regards,</p>
<p>Christian Di</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: SK Mody		</title>
		<link>https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-109615</link>

		<dc:creator><![CDATA[SK Mody]]></dc:creator>
		<pubDate>Sun, 16 Sep 2012 00:01:31 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2798#comment-109615</guid>

					<description><![CDATA[I stumbled upon this blog when trying to find out how property &#039;set&#039; methods are impacted if the property is an array. For example:
&lt;pre lang=&quot;matlab&quot;&gt;
classdef Collection
   properties
      array;
   end
   methods
      function This = set.array(This, s)
         % do something
         This.array = s;
      end
   end
end

C = Collection;
C.array = rand(2,2,1000);
C.array(1,1,3) = 5;
&lt;/pre&gt;

&#039;set&#039; is called for the indexed assignment, with an argument &#039;s&#039; which is a &#039;copy&#039; of This.array with exactly one element that is different. I was wondering Matlab could implement this sort of thing with a basic Copy on Write without causing some terrible inefficiencies. But reading the above I see that a more sophisticated COW could work reasonably.

Thanks.]]></description>
			<content:encoded><![CDATA[<p>I stumbled upon this blog when trying to find out how property &#8216;set&#8217; methods are impacted if the property is an array. For example:</p>
<pre lang="matlab">
classdef Collection
   properties
      array;
   end
   methods
      function This = set.array(This, s)
         % do something
         This.array = s;
      end
   end
end

C = Collection;
C.array = rand(2,2,1000);
C.array(1,1,3) = 5;
</pre>
<p>&#8216;set&#8217; is called for the indexed assignment, with an argument &#8216;s&#8217; which is a &#8216;copy&#8217; of This.array with exactly one element that is different. I was wondering Matlab could implement this sort of thing with a basic Copy on Write without causing some terrible inefficiencies. But reading the above I see that a more sophisticated COW could work reasonably.</p>
<p>Thanks.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Peter		</title>
		<link>https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-79279</link>

		<dc:creator><![CDATA[Peter]]></dc:creator>
		<pubDate>Tue, 27 Mar 2012 20:18:28 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2798#comment-79279</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-79250&quot;&gt;Martin&lt;/a&gt;.

Sounds very interesting Martin.  Indeed, the &quot;reference&quot; field is another particularly important subject that I believe was covered in part for older Matlab versions in a post by Benjamin Schubert: http://www.mk.tu-berlin.de/Members/Benjamin/mex_sharedArrays

I&#039;m not aware of any more up-to-date write-up of this however.  I would be particularly interested in better understanding how this interacts with mxUnshareArray and other copy-on-write mechanisms, some of which Benjamin&#039;s article goes into.

If my goal here was successful, perhaps you will find some of the simple tools here useful either in your investigations or else just in demonstrating your findings succinctly.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-79250">Martin</a>.</p>
<p>Sounds very interesting Martin.  Indeed, the &#8220;reference&#8221; field is another particularly important subject that I believe was covered in part for older Matlab versions in a post by Benjamin Schubert: <a href="http://www.mk.tu-berlin.de/Members/Benjamin/mex_sharedArrays" rel="nofollow ugc">http://www.mk.tu-berlin.de/Members/Benjamin/mex_sharedArrays</a></p>
<p>I&#8217;m not aware of any more up-to-date write-up of this however.  I would be particularly interested in better understanding how this interacts with mxUnshareArray and other copy-on-write mechanisms, some of which Benjamin&#8217;s article goes into.</p>
<p>If my goal here was successful, perhaps you will find some of the simple tools here useful either in your investigations or else just in demonstrating your findings succinctly.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Martin		</title>
		<link>https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-79250</link>

		<dc:creator><![CDATA[Martin]]></dc:creator>
		<pubDate>Tue, 27 Mar 2012 14:51:40 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2798#comment-79250</guid>

					<description><![CDATA[In fact I have something like &lt;i&gt;headerdump&lt;/i&gt; which works well with recent versions of MATLAB. I created it in order to reverse-engineer the internal representation of &lt;i&gt;mxArray&lt;/i&gt;. My original motivation for doing this was to be able to track MATLAB&#039;s memory allocation for big arrays because I&#039;m on a NUMA system and I wanted to be able to check/enforce that often used variables reside on node-local memory.

For example, MATLAB distinguishes between normal variables (as shown in this post), temporary variables (when you pass immediate values to a function), global/persistent variables, and variables embedded in cell arrays and structs. Concerning the latter, given this post you could assume that
&lt;pre lang=&quot;matlab&quot;&gt;x = repmat({ones(200)}, 1, 100);&lt;/pre&gt;
creates 100 doubly-linked instances of &lt;i&gt;mxArray&lt;/i&gt; (sharing the same data -- a 200&#215;200 matrix) for the entries of &lt;i&gt;x&lt;/i&gt;, but in fact there will be only one &lt;i&gt;mxArray&lt;/i&gt; with a reference count set to 100.

If there&#039;s sufficient interest I could imagine sharing my code (after some cleanup). Maybe I could also write a blog post similar to this one, but digging deeper into the internals (as far as I managed to understand them).]]></description>
			<content:encoded><![CDATA[<p>In fact I have something like <i>headerdump</i> which works well with recent versions of MATLAB. I created it in order to reverse-engineer the internal representation of <i>mxArray</i>. My original motivation for doing this was to be able to track MATLAB&#8217;s memory allocation for big arrays because I&#8217;m on a NUMA system and I wanted to be able to check/enforce that often used variables reside on node-local memory.</p>
<p>For example, MATLAB distinguishes between normal variables (as shown in this post), temporary variables (when you pass immediate values to a function), global/persistent variables, and variables embedded in cell arrays and structs. Concerning the latter, given this post you could assume that</p>
<pre lang="matlab">x = repmat({ones(200)}, 1, 100);</pre>
<p>creates 100 doubly-linked instances of <i>mxArray</i> (sharing the same data &#8212; a 200&times;200 matrix) for the entries of <i>x</i>, but in fact there will be only one <i>mxArray</i> with a reference count set to 100.</p>
<p>If there&#8217;s sufficient interest I could imagine sharing my code (after some cleanup). Maybe I could also write a blog post similar to this one, but digging deeper into the internals (as far as I managed to understand them).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Peter		</title>
		<link>https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-78518</link>

		<dc:creator><![CDATA[Peter]]></dc:creator>
		<pubDate>Wed, 21 Mar 2012 19:54:22 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2798#comment-78518</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-77876&quot;&gt;Laurens Bakker&lt;/a&gt;.

Thanks Laurens.  Yes what you say makes sense.  For some reason I was thinking about this in terms of traversing the cycle, but of course when we modify one element we must delete it from the cycle and that is the operation where the double linking will save you time (if your cycle is irrationally large :)).]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-77876">Laurens Bakker</a>.</p>
<p>Thanks Laurens.  Yes what you say makes sense.  For some reason I was thinking about this in terms of traversing the cycle, but of course when we modify one element we must delete it from the cycle and that is the operation where the double linking will save you time (if your cycle is irrationally large :)).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Laurens Bakker		</title>
		<link>https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation#comment-77876</link>

		<dc:creator><![CDATA[Laurens Bakker]]></dc:creator>
		<pubDate>Fri, 16 Mar 2012 18:40:35 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2798#comment-77876</guid>

					<description><![CDATA[Hi Peter,

Thanks for this nifty bit of detective work. You wondered why the cycle of identical arrays is stored as a doubly linked list. My guess is that it is probably done for time-efficiency. Suppose for some reason you create a million copies of a single array, and then modify a single one. In order to re-close the loop, you would have to iterate over the entire cycle to get both loose ends. With a doubly-linked list this can be done in constant time.

Cheers,

Laurens]]></description>
			<content:encoded><![CDATA[<p>Hi Peter,</p>
<p>Thanks for this nifty bit of detective work. You wondered why the cycle of identical arrays is stored as a doubly linked list. My guess is that it is probably done for time-efficiency. Suppose for some reason you create a million copies of a single array, and then modify a single one. In order to re-close the loop, you would have to iterate over the entire cycle to get both loose ends. With a doubly-linked list this can be done in constant time.</p>
<p>Cheers,</p>
<p>Laurens</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
