source: trunk/doc/html/qmemarray.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 27.4 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/qmemarray.doc:41 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QMemArray Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QMemArray Class Reference</h1>
33
34<p>The QMemArray class is a template class that provides arrays of simple types.
35<a href="#details">More...</a>
36<p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support.</p>
37<p><tt>#include &lt;<a href="qmemarray-h.html">qmemarray.h</a>&gt;</tt>
38<p>Inherited by <a href="qbytearray.html">QByteArray</a> and <a href="qpointarray.html">QPointArray</a>.
39<p><a href="qmemarray-members.html">List of all member functions.</a>
40<h2>Public Members</h2>
41<ul>
42<li class=fn>typedef type&nbsp;*&nbsp;<a href="#Iterator"><b>Iterator</b></a></li>
43<li class=fn>typedef const&nbsp;type&nbsp;*&nbsp;<a href="#ConstIterator"><b>ConstIterator</b></a></li>
44<li class=fn><a href="#QMemArray-2"><b>QMemArray</b></a> ()</li>
45<li class=fn><a href="#QMemArray-3"><b>QMemArray</b></a> ( int&nbsp;size )</li>
46<li class=fn><a href="#QMemArray-4"><b>QMemArray</b></a> ( const&nbsp;QMemArray&lt;type&gt;&nbsp;&amp;&nbsp;a )</li>
47<li class=fn><a href="#~QMemArray"><b>~QMemArray</b></a> ()</li>
48<li class=fn>QMemArray&lt;type&gt; &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;QMemArray&lt;type&gt;&nbsp;&amp;&nbsp;a )</li>
49<li class=fn>type * <a href="#data"><b>data</b></a> () const</li>
50<li class=fn>uint <a href="#nrefs"><b>nrefs</b></a> () const</li>
51<li class=fn>uint <a href="#size"><b>size</b></a> () const</li>
52<li class=fn>uint <a href="#count"><b>count</b></a> () const</li>
53<li class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</li>
54<li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
55<li class=fn>bool <a href="#resize-2"><b>resize</b></a> ( uint&nbsp;size )</li>
56<li class=fn>bool <a href="#resize"><b>resize</b></a> ( uint&nbsp;size, Optimization&nbsp;optim )</li>
57<li class=fn>bool <a href="#truncate"><b>truncate</b></a> ( uint&nbsp;pos )</li>
58<li class=fn>bool <a href="#fill"><b>fill</b></a> ( const&nbsp;type&nbsp;&amp;&nbsp;v, int&nbsp;size = -1 )</li>
59<li class=fn>virtual void <a href="#detach"><b>detach</b></a> ()</li>
60<li class=fn>QMemArray&lt;type&gt; <a href="#copy"><b>copy</b></a> () const</li>
61<li class=fn>QMemArray&lt;type&gt; &amp; <a href="#assign"><b>assign</b></a> ( const&nbsp;QMemArray&lt;type&gt;&nbsp;&amp;&nbsp;a )</li>
62<li class=fn>QMemArray&lt;type&gt; &amp; <a href="#assign-2"><b>assign</b></a> ( const&nbsp;type&nbsp;*&nbsp;data, uint&nbsp;size )</li>
63<li class=fn>QMemArray&lt;type&gt; &amp; <a href="#duplicate"><b>duplicate</b></a> ( const&nbsp;QMemArray&lt;type&gt;&nbsp;&amp;&nbsp;a )</li>
64<li class=fn>QMemArray&lt;type&gt; &amp; <a href="#duplicate-2"><b>duplicate</b></a> ( const&nbsp;type&nbsp;*&nbsp;data, uint&nbsp;size )</li>
65<li class=fn>QMemArray&lt;type&gt; &amp; <a href="#setRawData"><b>setRawData</b></a> ( const&nbsp;type&nbsp;*&nbsp;data, uint&nbsp;size )</li>
66<li class=fn>void <a href="#resetRawData"><b>resetRawData</b></a> ( const&nbsp;type&nbsp;*&nbsp;data, uint&nbsp;size )</li>
67<li class=fn>int <a href="#find"><b>find</b></a> ( const&nbsp;type&nbsp;&amp;&nbsp;v, uint&nbsp;index = 0 ) const</li>
68<li class=fn>int <a href="#contains"><b>contains</b></a> ( const&nbsp;type&nbsp;&amp;&nbsp;v ) const</li>
69<li class=fn>void <a href="#sort"><b>sort</b></a> ()</li>
70<li class=fn>int <a href="#bsearch"><b>bsearch</b></a> ( const&nbsp;type&nbsp;&amp;&nbsp;v ) const</li>
71<li class=fn>type &amp; <a href="#operator[]"><b>operator[]</b></a> ( int&nbsp;index ) const</li>
72<li class=fn>type &amp; <a href="#at"><b>at</b></a> ( uint&nbsp;index ) const</li>
73<li class=fn><a href="#operator-const-type-*"><b>operator const type *</b></a> () const</li>
74<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;QMemArray&lt;type&gt;&nbsp;&amp;&nbsp;a ) const</li>
75<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const&nbsp;QMemArray&lt;type&gt;&nbsp;&amp;&nbsp;a ) const</li>
76<li class=fn>Iterator <a href="#begin"><b>begin</b></a> ()</li>
77<li class=fn>Iterator <a href="#end"><b>end</b></a> ()</li>
78<li class=fn>ConstIterator <a href="#begin-2"><b>begin</b></a> () const</li>
79<li class=fn>ConstIterator <a href="#end-2"><b>end</b></a> () const</li>
80</ul>
81<h2>Protected Members</h2>
82<ul>
83<li class=fn><a href="#QMemArray"><b>QMemArray</b></a> ( int, int )</li>
84</ul>
85<h2>Related Functions</h2>
86<ul>
87<li class=fn>Q_UINT16 <a href="#qChecksum"><b>qChecksum</b></a> ( const&nbsp;char&nbsp;*&nbsp;data, uint&nbsp;len )</li>
88<li class=fn>QDataStream &amp; <a href="#operator-lt-lt"><b>operator&lt;&lt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, const&nbsp;QByteArray&nbsp;&amp;&nbsp;a )</li>
89<li class=fn>QDataStream &amp; <a href="#operator-gt-gt"><b>operator&gt;&gt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, QByteArray&nbsp;&amp;&nbsp;a )</li>
90</ul>
91<hr><a name="details"></a><h2>Detailed Description</h2>
92
93
94
95The QMemArray class is a template class that provides arrays of simple types.
96<p>
97<p> QMemArray is implemented as a template class. Define a template
98instance QMemArray&lt;X&gt; to create an array that contains X items.
99<p> QMemArray stores the array elements directly in the array. It can
100only deal with simple types (i.e. C++ types, structs, and classes
101that have no constructors, destructors, or virtual functions).
102QMemArray uses bitwise operations to copy and compare array
103elements.
104<p> The <a href="qptrvector.html">QPtrVector</a> collection class is also a kind of array. Like most
105<a href="collection.html">collection classes</a>, it uses pointers
106to the contained items.
107<p> QMemArray uses <a href="shclass.html">explicit sharing</a> with a
108reference count. If more than one array shares common data and one
109of the arrays is modified, all the arrays are modified.
110<p> The benefit of sharing is that a program does not need to duplicate
111data when it is not required, which results in lower memory use
112and less copying of data.
113<p> An alternative to QMemArray is <a href="qvaluevector.html">QValueVector</a>. The QValueVector class
114also provides an array of objects, but can deal with objects that
115have constructors (specifically a copy constructor and a default
116constructor). QValueVector provides an STL-compatible syntax and is
117<a href="shclass.html">implicitly shared</a>.
118<p> Example:
119<pre>
120 #include &lt;<a href="qmemarray-h.html">qmemarray.h</a>&gt;
121 #include &lt;stdio.h&gt;
122
123 QMemArray&lt;int&gt; fib( int num ) // returns fibonacci array
124 {
125 <a href="qapplication.html#Q_ASSERT">Q_ASSERT</a>( num &gt; 2 );
126 QMemArray&lt;int&gt; f( num ); // array of ints
127
128 f[0] = f[1] = 1;
129 for ( int i = 2; i &lt; num; i++ )
130 f[i] = f[i-1] + f[i-2];
131
132 return f;
133 }
134
135 int main()
136 {
137 QMemArray&lt;int&gt; a = fib( 6 ); // get first 6 fibonaccis
138 for ( int i = 0; i &lt; a.<a href="#size">size</a>(); i++ )
139 <a href="qapplication.html#qDebug">qDebug</a>( "%d: %d", i, a[i] );
140
141 <a href="qapplication.html#qDebug">qDebug</a>( "1 is found %d times", a.<a href="#contains">contains</a>(1) );
142 <a href="qapplication.html#qDebug">qDebug</a>( "5 is found at index %d", a.<a href="#find">find</a>(5) );
143
144 return 0;
145 }
146 </pre>
147
148<p> Program output:
149<pre>
150 0: 1
151 1: 1
152 2: 2
153 3: 3
154 4: 5
155 5: 8
156 1 is found 2 times
157 5 is found at index 4
158 </pre>
159
160<p> Note concerning the use of QMemArray for manipulating structs or
161classes: Compilers will often pad the size of structs of odd sizes
162up to the nearest word boundary. This will then be the size
163QMemArray will use for its bitwise element comparisons. Because
164the remaining bytes will typically be uninitialized, this can
165cause <a href="#find">find</a>() etc. to fail to find the element. Example:
166<p> <pre>
167 // MyStruct may be padded to 4 or 8 bytes
168 struct MyStruct
169 {
170 short i; // 2 bytes
171 char c; // 1 byte
172 };
173
174 QMemArray&lt;MyStruct&gt; a(1);
175 a[0].i = 5;
176 a[0].c = 't';
177
178 MyStruct x;
179 x.i = '5';
180 x.c = 't';
181 int i = a.<a href="#find">find</a>( x ); // may return -1 if the pad bytes differ
182 </pre>
183
184<p> To work around this, make sure that you use a struct where
185sizeof() returns the same as the sum of the sizes of the members
186either by changing the types of the struct members or by adding
187dummy members.
188<p> QMemArray data can be traversed by iterators (see <a href="#begin">begin</a>() and
189<a href="#end">end</a>()). The number of items is returned by <a href="#count">count</a>(). The array can
190be resized with <a href="#resize">resize</a>() and filled using <a href="#fill">fill</a>().
191<p> You can make a <a href="shclass.html#shallow-copy">shallow copy</a> of the array with <a href="#assign">assign</a>() (or
192<a href="#operator-eq">operator=</a>()) and a <a href="shclass.html#deep-copy">deep copy</a> with <a href="#duplicate">duplicate</a>().
193<p> Search for values in the array with <a href="#find">find</a>() and <a href="#contains">contains</a>(). For
194sorted arrays (see <a href="#sort">sort</a>()) you can search using <a href="#bsearch">bsearch</a>().
195<p> You can set the data directly using <a href="#setRawData">setRawData</a>() and
196<a href="#resetRawData">resetRawData</a>(), although this requires care.
197<p> <p>See also <a href="shclass.html">Shared Classes</a> and <a href="tools.html">Non-GUI Classes</a>.
198
199<hr><h2>Member Type Documentation</h2>
200<h3 class=fn><a name="ConstIterator"></a>QMemArray::ConstIterator</h3>
201A const QMemArray iterator.
202<p>See also <a href="#begin">begin</a>() and <a href="#end">end</a>().
203
204<h3 class=fn><a name="Iterator"></a>QMemArray::Iterator</h3>
205A QMemArray iterator.
206<p>See also <a href="#begin">begin</a>() and <a href="#end">end</a>().
207
208<hr><h2>Member Function Documentation</h2>
209<h3 class=fn><a name="QMemArray"></a>QMemArray::QMemArray ( int, int )<tt> [protected]</tt>
210</h3>
211
212<p> Constructs an array <em>without allocating</em> array space. The
213arguments should be (0, 0). Use at your own risk.
214
215<h3 class=fn><a name="QMemArray-2"></a>QMemArray::QMemArray ()
216</h3>
217
218<p> Constructs a null array.
219<p> <p>See also <a href="#isNull">isNull</a>().
220
221<h3 class=fn><a name="QMemArray-3"></a>QMemArray::QMemArray ( int&nbsp;size )
222</h3>
223
224<p> Constructs an array with room for <em>size</em> elements. Makes a null
225array if <em>size</em> == 0.
226<p> The elements are left uninitialized.
227<p> <p>See also <a href="#resize">resize</a>() and <a href="#isNull">isNull</a>().
228
229<h3 class=fn><a name="QMemArray-4"></a>QMemArray::QMemArray ( const&nbsp;<a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp;&nbsp;a )
230</h3>
231
232<p> Constructs a <a href="shclass.html#shallow-copy">shallow copy</a> of <em>a</em>.
233<p> <p>See also <a href="#assign">assign</a>().
234
235<h3 class=fn><a name="~QMemArray"></a>QMemArray::~QMemArray ()
236</h3>
237
238<p> Dereferences the array data and deletes it if this was the last
239reference.
240
241<h3 class=fn><a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp; <a name="assign"></a>QMemArray::assign ( const&nbsp;<a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp;&nbsp;a )
242</h3>
243
244<p> <a href="shclass.html#shallow-copy">Shallow copy</a>. Dereferences the current array and references the
245data contained in <em>a</em> instead. Returns a reference to this array.
246<p> <p>See also <a href="#operator-eq">operator=</a>().
247
248<h3 class=fn><a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp; <a name="assign-2"></a>QMemArray::assign ( const&nbsp;type&nbsp;*&nbsp;data, uint&nbsp;size )
249</h3>
250
251<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
252<p> <a href="shclass.html#shallow-copy">Shallow copy</a>. Dereferences the current array and references the
253array data <em>data</em>, which contains <em>size</em> elements. Returns a
254reference to this array.
255<p> Do not delete <em>data</em> later; QMemArray will call free() on it
256at the right time.
257
258<h3 class=fn>type &amp; <a name="at"></a>QMemArray::at ( uint&nbsp;index ) const
259</h3>
260
261<p> Returns a reference to the element at position <em>index</em> in the array.
262<p> This can be used to both read and set an element.
263<p> <p>See also <a href="#operator[]">operator[]</a>().
264
265<h3 class=fn><a href="qmemarray.html#Iterator">Iterator</a> <a name="begin"></a>QMemArray::begin ()
266</h3>
267
268<p> Returns an iterator pointing at the beginning of this array. This
269iterator can be used in the same way as the iterators of
270<a href="qvaluelist.html">QValueList</a> and <a href="qmap.html">QMap</a>, for example.
271
272<h3 class=fn><a href="qmemarray.html#ConstIterator">ConstIterator</a> <a name="begin-2"></a>QMemArray::begin () const
273</h3>
274
275<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
276<p> Returns a const iterator pointing at the beginning of this array.
277This iterator can be used in the same way as the iterators of
278<a href="qvaluelist.html">QValueList</a> and <a href="qmap.html">QMap</a>, for example.
279
280<h3 class=fn>int <a name="bsearch"></a>QMemArray::bsearch ( const&nbsp;type&nbsp;&amp;&nbsp;v ) const
281</h3>
282
283<p> In a sorted array (as sorted by <a href="#sort">sort</a>()), finds the first
284occurrence of <em>v</em> by using a binary search. For a sorted
285array this is generally much faster than <a href="#find">find</a>(), which does
286a linear search.
287<p> Returns the position of <em>v</em>, or -1 if <em>v</em> could not be found.
288<p> <p>See also <a href="#sort">sort</a>() and <a href="#find">find</a>().
289
290<h3 class=fn>int <a name="contains"></a>QMemArray::contains ( const&nbsp;type&nbsp;&amp;&nbsp;v ) const
291</h3>
292
293<p> Returns the number of times <em>v</em> occurs in the array.
294<p> <p>See also <a href="#find">find</a>().
295
296<h3 class=fn><a href="qmemarray.html">QMemArray</a>&lt;type&gt; <a name="copy"></a>QMemArray::copy () const
297</h3>
298
299<p> Returns a <a href="shclass.html#deep-copy">deep copy</a> of this array.
300<p> <p>See also <a href="#detach">detach</a>() and <a href="#duplicate">duplicate</a>().
301
302<h3 class=fn>uint <a name="count"></a>QMemArray::count () const
303</h3>
304
305<p> Returns the same as <a href="#size">size</a>().
306<p> <p>See also <a href="#size">size</a>().
307
308<p>Example: <a href="scribble-example.html#x913">scribble/scribble.cpp</a>.
309<h3 class=fn>type * <a name="data"></a>QMemArray::data () const
310</h3>
311
312<p> Returns a pointer to the actual array data.
313<p> The array is a null array if <a href="#data">data</a>() == 0 (null pointer).
314<p> <p>See also <a href="#isNull">isNull</a>().
315
316<p>Examples: <a href="fileiconview-example.html#x855">fileiconview/qfileiconview.cpp</a> and <a href="networkprotocol-example.html#x671">network/networkprotocol/nntp.cpp</a>.
317<h3 class=fn>void <a name="detach"></a>QMemArray::detach ()<tt> [virtual]</tt>
318</h3>
319
320<p> Detaches this array from shared array data; i.e. it makes a
321private, <a href="shclass.html#deep-copy">deep copy</a> of the data.
322<p> Copying will be performed only if the <a href="#nrefs">reference
323 count</a> is greater than one.
324<p> <p>See also <a href="#copy">copy</a>().
325
326<p>Reimplemented in <a href="qbitarray.html#detach">QBitArray</a>.
327<h3 class=fn><a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp; <a name="duplicate"></a>QMemArray::duplicate ( const&nbsp;<a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp;&nbsp;a )
328</h3>
329
330<p> <a href="shclass.html#deep-copy">Deep copy</a>. Dereferences the current array and obtains a copy of
331the data contained in <em>a</em> instead. Returns a reference to this
332array.
333<p> <p>See also <a href="#copy">copy</a>().
334
335<h3 class=fn><a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp; <a name="duplicate-2"></a>QMemArray::duplicate ( const&nbsp;type&nbsp;*&nbsp;data, uint&nbsp;size )
336</h3>
337
338<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
339<p> <a href="shclass.html#deep-copy">Deep copy</a>. Dereferences the current array and obtains a copy of
340the array data <em>data</em> instead. Returns a reference to this array.
341The size of the array is given by <em>size</em>.
342<p> <p>See also <a href="#copy">copy</a>().
343
344<h3 class=fn><a href="qmemarray.html#Iterator">Iterator</a> <a name="end"></a>QMemArray::end ()
345</h3>
346
347<p> Returns an iterator pointing behind the last element of this
348array. This iterator can be used in the same way as the iterators
349of <a href="qvaluelist.html">QValueList</a> and <a href="qmap.html">QMap</a>, for example.
350
351<h3 class=fn><a href="qmemarray.html#ConstIterator">ConstIterator</a> <a name="end-2"></a>QMemArray::end () const
352</h3>
353
354<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
355<p> Returns a const iterator pointing behind the last element of this
356array. This iterator can be used in the same way as the iterators
357of <a href="qvaluelist.html">QValueList</a> and <a href="qmap.html">QMap</a>, for example.
358
359<h3 class=fn>bool <a name="fill"></a>QMemArray::fill ( const&nbsp;type&nbsp;&amp;&nbsp;v, int&nbsp;size = -1 )
360</h3>
361
362<p> Fills the array with the value <em>v</em>. If <em>size</em> is specified as
363different from -1, then the array will be resized before being
364filled.
365<p> Returns TRUE if successful, i.e. if <em>size</em> is -1, or <em>size</em> is
366!= -1 and the memory can be allocated; otherwise returns FALSE.
367<p> <p>See also <a href="#resize">resize</a>().
368
369<h3 class=fn>int <a name="find"></a>QMemArray::find ( const&nbsp;type&nbsp;&amp;&nbsp;v, uint&nbsp;index = 0 ) const
370</h3>
371
372<p> Finds the first occurrence of <em>v</em>, starting at position <em>index</em>.
373<p> Returns the position of <em>v</em>, or -1 if <em>v</em> could not be found.
374<p> <p>See also <a href="#contains">contains</a>().
375
376<h3 class=fn>bool <a name="isEmpty"></a>QMemArray::isEmpty () const
377</h3>
378
379<p> Returns TRUE if the array is empty; otherwise returns FALSE.
380<p> <a href="#isEmpty">isEmpty</a>() is equivalent to <a href="#isNull">isNull</a>() for QMemArray (unlike
381<a href="qstring.html">QString</a>).
382
383<h3 class=fn>bool <a name="isNull"></a>QMemArray::isNull () const
384</h3>
385
386<p> Returns TRUE if the array is null; otherwise returns FALSE.
387<p> A null array has <a href="#size">size</a>() == 0 and <a href="#data">data</a>() == 0.
388
389<h3 class=fn>uint <a name="nrefs"></a>QMemArray::nrefs () const
390</h3>
391
392<p> Returns the reference count for the shared array data. This
393reference count is always greater than zero.
394
395<h3 class=fn><a name="operator-const-type-*"></a>QMemArray::operator const type * () const
396</h3>
397
398<p> Cast operator. Returns a pointer to the array.
399<p> <p>See also <a href="#data">data</a>().
400
401<h3 class=fn>bool <a name="operator!-eq"></a>QMemArray::operator!= ( const&nbsp;<a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp;&nbsp;a ) const
402</h3>
403
404<p> Returns TRUE if this array is different from <em>a</em>; otherwise
405returns FALSE.
406<p> The two arrays are compared bitwise.
407<p> <p>See also <a href="#operator-eq-eq">operator==</a>().
408
409<h3 class=fn><a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp; <a name="operator-eq"></a>QMemArray::operator= ( const&nbsp;<a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp;&nbsp;a )
410</h3>
411
412<p> Assigns a <a href="shclass.html#shallow-copy">shallow copy</a> of <em>a</em> to this array and returns a
413reference to this array.
414<p> Equivalent to <a href="#assign">assign</a>( a ).
415
416<h3 class=fn>bool <a name="operator-eq-eq"></a>QMemArray::operator== ( const&nbsp;<a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp;&nbsp;a ) const
417</h3>
418
419<p> Returns TRUE if this array is equal to <em>a</em>; otherwise returns
420FALSE.
421<p> The two arrays are compared bitwise.
422<p> <p>See also <a href="#operator!-eq">operator!=</a>().
423
424<h3 class=fn>type &amp; <a name="operator[]"></a>QMemArray::operator[] ( int&nbsp;index ) const
425</h3>
426
427<p> Returns a reference to the element at position <em>index</em> in the
428array.
429<p> This can be used to both read and set an element. Equivalent to
430<a href="#at">at</a>().
431<p> <p>See also <a href="#at">at</a>().
432
433<h3 class=fn>void <a name="resetRawData"></a>QMemArray::resetRawData ( const&nbsp;type&nbsp;*&nbsp;data, uint&nbsp;size )
434</h3>
435
436<p> Removes internal references to the raw data that was set using
437<a href="#setRawData">setRawData</a>(). This means that QMemArray no longer has access to
438the <em>data</em>, so you are free to manipulate <em>data</em> as you wish.
439You can now use the QMemArray without affecting the original <em>data</em>, for example by calling setRawData() with a pointer to some
440other data.
441<p> The arguments must be the <em>data</em> and length, <em>size</em>, that were
442passed to setRawData(). This is for consistency checking.
443<p> <p>See also <a href="#setRawData">setRawData</a>().
444
445<h3 class=fn>bool <a name="resize"></a>QMemArray::resize ( uint&nbsp;size, Optimization&nbsp;optim )
446</h3>
447
448<p> Resizes (expands or shrinks) the array to <em>size</em> elements. The
449array becomes a null array if <em>size</em> == 0.
450<p> Returns TRUE if successful, or FALSE if the memory cannot be
451allocated.
452<p> New elements are not initialized.
453<p> <em>optim</em> is either <tt>QGArray::MemOptim</tt> (the default) or
454<tt>QGArray::SpeedOptim</tt>.
455<p> <b>Note:</b> By default, <tt>SpeedOptim</tt> is not available for general
456use since it is only available if Qt is built in a particular
457configuration.
458<p> <p>See also <a href="#size">size</a>().
459
460<p>Example: <a href="fileiconview-example.html#x856">fileiconview/qfileiconview.cpp</a>.
461<h3 class=fn>bool <a name="resize-2"></a>QMemArray::resize ( uint&nbsp;size )
462</h3>
463
464<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
465<p> Resizes (expands or shrinks) the array to <em>size</em> elements. The
466array becomes a null array if <em>size</em> == 0.
467<p> Returns TRUE if successful, i.e. if the memory can be allocated;
468otherwise returns FALSE.
469<p> New elements are not initialized.
470<p> <p>See also <a href="#size">size</a>().
471
472<h3 class=fn><a href="qmemarray.html">QMemArray</a>&lt;type&gt;&nbsp;&amp; <a name="setRawData"></a>QMemArray::setRawData ( const&nbsp;type&nbsp;*&nbsp;data, uint&nbsp;size )
473</h3>
474
475<p> Sets raw data and returns a reference to the array.
476<p> Dereferences the current array and sets the new array data to <em>data</em> and the new array size to <em>size</em>. Do not attempt to resize
477or re-assign the array data when raw data has been set. Call
478<a href="#resetRawData">resetRawData</a>(<em>data</em>, <em>size</em>) to reset the array.
479<p> Setting raw data is useful because it sets QMemArray data without
480allocating memory or copying data.
481<p> Example I (intended use):
482<pre>
483 static char bindata[] = { 231, 1, 44, ... };
484 <a href="qbytearray.html">QByteArray</a> a;
485 a.<a href="#setRawData">setRawData</a>( bindata, sizeof(bindata) ); // a points to bindata
486 <a href="qdatastream.html">QDataStream</a> s( a, <a href="qfile.html#open">IO_ReadOnly</a> ); // open on a's data
487 s &gt;&gt; &lt;something&gt;; // read raw bindata
488 a.<a href="#resetRawData">resetRawData</a>( bindata, sizeof(bindata) ); // finished
489 </pre>
490
491<p> Example II (you don't want to do this):
492<pre>
493 static char bindata[] = { 231, 1, 44, ... };
494 <a href="qbytearray.html">QByteArray</a> a, b;
495 a.<a href="#setRawData">setRawData</a>( bindata, sizeof(bindata) ); // a points to bindata
496 a.<a href="#resize">resize</a>( 8 ); // will crash
497 b = a; // will crash
498 a[2] = 123; // might crash
499 // forget to resetRawData: will crash
500 </pre>
501
502<p> <b>Warning:</b> If you do not call <a href="#resetRawData">resetRawData</a>(), QMemArray will attempt
503to deallocate or reallocate the raw data, which might not be too
504good. Be careful.
505<p> <p>See also <a href="#resetRawData">resetRawData</a>().
506
507<h3 class=fn>uint <a name="size"></a>QMemArray::size () const
508</h3>
509
510<p> Returns the size of the array (maximum number of elements).
511<p> The array is a null array if <a href="#size">size</a>() == 0.
512<p> <p>See also <a href="#isNull">isNull</a>() and <a href="#resize">resize</a>().
513
514<h3 class=fn>void <a name="sort"></a>QMemArray::sort ()
515</h3>
516
517<p> Sorts the array elements in ascending order, using bitwise
518comparison (memcmp()).
519<p> <p>See also <a href="#bsearch">bsearch</a>().
520
521<h3 class=fn>bool <a name="truncate"></a>QMemArray::truncate ( uint&nbsp;pos )
522</h3>
523
524<p> Truncates the array at position <em>pos</em>.
525<p> Returns TRUE if successful, i.e. if the memory can be allocated;
526otherwise returns FALSE.
527<p> Equivalent to <a href="#resize">resize</a>(<em>pos</em>).
528<p> <p>See also <a href="#resize">resize</a>().
529
530<hr><h2>Related Functions</h2>
531<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt"></a>operator&lt;&lt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, const&nbsp;<a href="qbytearray.html">QByteArray</a>&nbsp;&amp;&nbsp;a )
532</h3>
533
534<p> Writes byte array <em>a</em> to the stream <em>s</em> and returns a reference
535to the stream.
536<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
537
538<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt"></a>operator&gt;&gt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, <a href="qbytearray.html">QByteArray</a>&nbsp;&amp;&nbsp;a )
539</h3>
540
541<p> Reads a byte array into <em>a</em> from the stream <em>s</em> and returns a
542reference to the stream.
543<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
544
545<h3 class=fn>Q_UINT16 <a name="qChecksum"></a>qChecksum ( const&nbsp;char&nbsp;*&nbsp;data, uint&nbsp;len )
546</h3>
547
548<p> Returns the CRC-16 checksum of <em>len</em> bytes starting at <em>data</em>.
549<p> The checksum is independent of the byte order (endianness).
550
551<!-- eof -->
552<hr><p>
553This file is part of the <a href="index.html">Qt toolkit</a>.
554Copyright &copy; 1995-2007
555<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
556<table width=100% cellspacing=0 border=0><tr>
557<td>Copyright &copy; 2007
558<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
559<td align=right><div align=right>Qt 3.3.8</div>
560</table></div></address></body>
561</html>
Note: See TracBrowser for help on using the repository browser.