<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - Native Container Classes
</title>
</head>
<body>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help%3Fen"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;&nbsp;
<a href="../cat%3Fen">Up</a>&nbsp;&nbsp;
<a href="constants%3Fen">Previous</a>&nbsp;&nbsp;
<a href="conv%3Fen">Next</a>&nbsp;&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Native Container Classes
</h1>
<a href="../def/gambas%3Fen">Gambas</a> interpreter offers you three kinds of native container classes:
<p>
<h2>Arrays</h2>
<p>
An <a href="../lang/array%3Fen">Inline Arrays</a> is a set of values indexed by an <a href="../lang/type/integer%3Fen">Integer</a> that are
consecutive in memory.
<p>
All the values in an array have the same datatype, and there is one
array class for each native datatype, except <a href="../lang/type/boolean%3Fen">Boolean</a>.
<p>
See <a href="array%3Fen">Native Arrays</a> for more information.
<p>
<a href="../lang/array%3Fen">Inline Arrays</a> can be multi-dimensional, i.e. values are indexed by more than one <a href="../lang/type/integer%3Fen">Integer</a>.
<p>
If an array has one dimension, then it can be shrinked or expanded dynamically, with
the <a href="../comp/gb/_array/resize%3Fen">Resize</a> method.
<p>
<h2>Lists</h2>
<p>
A <a href="../comp/gb/list%3Fen">List</a> is a double-linked list of values indexed by an <a href="../lang/type/integer%3Fen">Integer</a>,
each one being stored separately in memory.
<p>
Only <a href="../lang/type/variant%3Fen">Variant</a> values can be stored in a <a href="../comp/gb/list%3Fen">List</a>.
<p>
The <a href="../comp/gb/list%3Fen">List</a> maintains a internal pointer so that finding a position in the list does not
imply iterates all the elements.
<p>
<h2>Collections</h2>
<p>
A <a href="../comp/gb/collection%3Fen">Collection</a> is a set of values indexed by a <a href="../comp/gb/string%3Fen">String</a>.
<p>
Only <a href="../lang/type/variant%3Fen">Variant</a> values can be stored in a <a href="../comp/gb/collection%3Fen">Collection</a>.
<p>
The values are internally stored in a hash table that grows dynamically
when more and more elements are inserted in it.
<p>
<h2>Which one use ?</h2>
<p>
Here is a short comparison between the three kind of container classes:
<p>
<div class="gray"><font color="white" size="-2"><b>Container Comparison Chart
</b></font></div><table class="table" border="0" bordercolor="#000000" cellpadding="4" cellspacing="0">
<tr><th>
<p>
</th><th>
<a href="../lang/array%3Fen">Inline Arrays</a>
</th><th>
<a href="../comp/gb/list%3Fen">List</a>
</th><th>
<a href="../comp/gb/collection%3Fen">Collection</a>
</th></tr>
<tr bgcolor="white"><td valign="top">
<b>Internal storage</b>
</td><td valign="top">
Memory block.
</td><td valign="top">
Double linked-list.
</td><td valign="top">
Hash table.
</td></tr>
<tr><td valign="top">
<b>Key datatype</b>
</td><td valign="top">
<a href="../lang/type/integer%3Fen">Integer</a>
</td><td valign="top">
<a href="../lang/type/integer%3Fen">Integer</a>
</td><td valign="top">
<a href="../comp/gb/string%3Fen">String</a>
</td></tr>
<tr bgcolor="white"><td valign="top">
<b>Access speed</b>
</td><td valign="top">
<u><b>Fastest</b></u>
<p>
The access is immediate.
</td><td valign="top">
<u>Fast</u>
<p>
Accessing the first, last, previous or next element is immediate.
Otherwise the list is enumerated.
</td><td valign="top">
<u>Fast</u>
<p>
The key must be compared with all other keys having the same hash code.
</td></tr>
<tr><td valign="top">
<b>Insertion speed</b>
</td><td valign="top">
<u>Slow</u>
<p>
The memory block is resized if needed. And inserting in the middle of
the array needs moving part of the memory block.
</td><td valign="top">
<u><b>Fastest</b></u>
<p>
Once the position is found, the insertion is immediate.
</td><td valign="top">
<u>Fast</u>
<p>
The key hash code gives a index into a linked list of memory slots.
<p>
The hash table have to be resized and recalculated sometimes
to keep the access fast.
</td></tr>
<tr bgcolor="white"><td valign="top">
<b>Deletion speed</b>
</td><td valign="top">
<u>Slow</u>
<p>
The memory block is resized if needed. And deleting in the middle of
the array needs moving part of the memory block.
</td><td valign="top">
<u><b>Fastest</b></u>
<p>
Once the element is found, the deletion is immediate.
</td><td valign="top">
<u>Fast</u>
<p>
Once the element is found, the deletion is immediate.
<p>
The hash table have to be resized and recalculated sometimes
to keep the access fast.
</td></tr>
</table>
<p>

<p>
<hr><b>See also</b><br>
<a href="../comp/gb/byte[]%3Fen">Byte[]</a>&nbsp;&nbsp; <a href="../comp/gb/short[]%3Fen">Short[]</a>&nbsp;&nbsp; <a href="../comp/gb/integer[]%3Fen">Integer[]</a>&nbsp;&nbsp;
<a href="../comp/gb/long[]%3Fen">Long[]</a>&nbsp;&nbsp; <a href="../comp/gb/single[]%3Fen">Single[]</a>&nbsp;&nbsp; <a href="../comp/gb/float[]%3Fen">Float[]</a>&nbsp;&nbsp; <a href="../comp/gb/date[]%3Fen">Date[]</a>&nbsp;&nbsp;
<a href="../comp/gb/string[]%3Fen">String[]</a>&nbsp;&nbsp; <a href="../comp/gb/object[]%3Fen">Object[]</a>&nbsp;&nbsp; <a href="../comp/gb/variant[]%3Fen">Variant[]</a>&nbsp;&nbsp;
<a href="../comp/gb/list%3Fen">List</a>&nbsp;&nbsp;<a href="../comp/gb/collection%3Fen">Collection</a>&nbsp;&nbsp;

</div>
<hr>
</body>
</html>

