<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<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>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help+en"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../cat+en">Up</a>&nbsp;
<a href="constants+en">Previous</a>&nbsp;
<a href="conv+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Native Container Classes
</h1>
The <a href="../def/gambas+en">Gambas</a> interpreter offers you two types of native container classes:
<p>
<h2>Arrays</h2>
<p>
An <a href="../lang/array+en">Inline Arrays</a> is a set of values indexed by an <a href="../lang/type/integer+en">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+en">Boolean</a>.
<p>
See <a href="array+en">Native Arrays</a> for more information.
<p>
<a href="../lang/array+en">Inline Arrays</a> can be multi-dimensional, i.e. values are indexed by more than one <a href="../lang/type/integer+en">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+en">Resize</a> method.
<p>
<h2>Collections</h2>
<p>
A <a href="../comp/gb/collection+en">Collection</a> is a set of values indexed by a <a href="../comp/gb/string+en">String</a>.
<p>
Only <a href="../lang/type/variant+en">Variant</a> values can be stored in a <a href="../comp/gb/collection+en">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 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+en">Inline Arrays</a>
</th><th>
<a href="../comp/gb/collection+en">Collection</a>
</th></tr>
<tr class="dark"><td valign="top">
<b>Internal storage</b>
</td><td valign="top">
One memory block.
</td><td valign="top">
Hash table.
<p>
It means one array of slots, each one being a linked list of values having the same hash code.
</td></tr>
<tr><td valign="top">
<b>Key datatype</b>
</td><td valign="top">
<a href="../lang/type/integer+en">Integer</a>
</td><td valign="top">
<a href="../comp/gb/string+en">String</a>
</td></tr>
<tr class="dark"><td valign="top">
<b>Access speed</b>
</td><td valign="top">
<u>Immediate</u>
<p>
The access is immediate.
</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>Immediate</u> or <u>Slow</u>
<p>
The memory block is sometimes resized if needed. And inserting in the middle of
the array needs moving part of the memory block.
</td><td valign="top">
<u>Fast</u> or <u>Slow</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 class="dark"><td valign="top">
<b>Deletion speed</b>
</td><td valign="top">
<u>Immediate</u> or <u>Slow</u>
<p>
The memory block is sometimes resized if needed. And deleting in the middle of
the array needs moving part of the memory block.
</td><td valign="top">
<u>Fast</u> or <u>Slow</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[]+en">Byte[]</a>&nbsp; <a href="../comp/gb/short[]+en">Short[]</a>&nbsp; <a href="../comp/gb/integer[]+en">Integer[]</a>&nbsp;
<a href="../comp/gb/long[]+en">Long[]</a>&nbsp; <a href="../comp/gb/single[]+en">Single[]</a>&nbsp; <a href="../comp/gb/float[]+en">Float[]</a>&nbsp; <a href="../comp/gb/date[]+en">Date[]</a>&nbsp;
<a href="../comp/gb/string[]+en">String[]</a>&nbsp; <a href="../comp/gb/object[]+en">Object[]</a>&nbsp; <a href="../comp/gb/variant[]+en">Variant[]</a>&nbsp;
<a href="../comp/gb/collection+en">Collection</a>&nbsp;

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

