mozilla

Compare Revisions

Working with data

Change Revisions

Revision 98260:

Revision 98260 by Sheppy on

Revision 98261:

Revision 98261 by Sheppy on

Title:
Working with data
Working with data
Slug:
Mozilla/js-ctypes/Using_js-ctypes/Working_with_data
Mozilla/js-ctypes/Using_js-ctypes/Working_with_data
Tags:
JavaScript, js-ctypes
JavaScript, js-ctypes
Content:

Revision 98260
Revision 98261
tt96      Objects can share memory
97    </h2>
98    <p>
99      It's important to keep in mind that two (or more) <code>CDa
 >ta</code> objects can share the same memory block for their conte
 >nts. This will happen, for example, when <a href="/en/js-ctypes/U
 >sing_js-ctypes/Working_with_data#Type_casting" title="en/js-ctype
 >s/Using js-ctypes/Working with data#Type casting">type casting</a
 >>. This is called <strong>aliasing</strong>. The shared memory ca
 >n be whole or in part.
100    </p>
101    <p>
102      For example:
103    </p>
104    <pre class="brush: js">
105const Point = new ctypes.StructType("Point", [[ctypes.int32_t, 'x
 >'], [ctypes.int32_t, 'y']]);
106const Rect = new ctypes.StructType("Rect", [[Point, 'topLeft'], [
 >Point, 'bottomRight']]);
107 
108var r = Rect();
109var p = r.topLeft;
110r.topLeft.x = 100; 
111</pre>
112    <p>
113      At this point, <code>p</code> is a reference to the <code>t
 >opLeft</code> field in the <code>Rect</code> named <code>r</code>
 >. Setting the value of <code>p.x</code> will affect the value of 
 ><code>r.topLeft.x</code>, as expected.
114    </p>
115    <h2>

Back to History