Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation
Components
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
Documents
Error Messages
Gambas Playground
How To's
Language Index
Language Overviews
Arithmetical Functions
Arithmetic Operators
Array Declaration
Assignment Operators
Assignments
Binary Data Representation
Bits Manipulation Functions
Character Test Functions
Comparison methods
Complex numbers
Constant Declaration
Constant Expression
Conversion Functions
Datatype Functions
Datatypes
Date & Time Functions
Enumeration declaration
Error Management
Event Loop
Event Management
Events declaration
Expressions
External Function Management
File & Directory Functions
File & Directory Paths
File mode syntax
Floating Point Numbers
Formatting functions
Gambas Object Model
Global Special Event Handlers
Integer numbers
Intrinsic Functions
Language Constants
Localization and Translation Functions
Local Variable Declaration
Logarithms & Exponentials Functions
Logical Operators
Loop Control Structures
Method Declaration
Miscellaneous Control Structures
Miscellaneous Functions
Native Arrays
Native Container Classes
Object & Class Management
Operator Evaluation Order
Predefined Constants
Process Management
Property Declaration
Random Numbers Functions
Special Methods
Stream & Input/Output functions
String Functions
String Operators
Structure declaration
Test Control Structures & Functions
Trigonometric Functions
User-defined formats
Using reserved keywords as identifiers
Variable Declaration
Last Changes
Lexicon
README
Search the wiki
To Do
Topics
Tutorials
Wiki License
Wiki Manual

Native Container Classes

The Gambas interpreter offers you two types of native container classes:

Arrays

An array is a set of values indexed by an Integer that are consecutive in memory.

All the values in an array have the same datatype, and there is one array class for each native datatype.

See Native Arrays for more information.

Arrays can be multi-dimensional, i.e. values are indexed by more than one Integer.

If an array has one dimension, then it can be shrinked or expanded dynamically, with the Resize method.

Collections

A Collection is a set of values indexed by a String.

Only Variant values can be stored in a Collection.

The values are internally stored in a hash table that grows dynamically when more and more elements are inserted in it.

Which one to use ?

Here is a short comparison between the two kinds of container classes:

Array Collection
Internal storage One memory block. Hash table.

It means one array of slots, each one being a linked list of values having the same hash code.
Key datatype Integer String
Access speed Immediate

The access is immediate.
Fast

The key must be compared with all other keys having the same hash code.
Insertion speed Immediate or Slow

The memory block is sometimes resized if needed. And inserting in the middle of the array needs moving part of the memory block.
Fast or Slow

The key hash code gives a index into a linked list of memory slots.

The hash table have to be resized and recalculated sometimes to keep the access fast.
Deletion speed Immediate or Slow

The memory block is sometimes resized if needed. And deleting in the middle of the array needs moving part of the memory block.
Fast or Slow

Once the element is found, the deletion is immediate.

The hash table have to be resized and recalculated sometimes to keep the access fast.

See also