Arrays
On this page, we will cover arrays, their memory layouts, and how arrays work
What are arrays?
In Radon, an array is a fixed-size sequence of elements of the same data type, such as integers or characters. Elements are stored in contiguous memory locations, and each element can be accessed by its index, which is an integer value that starts at 0.
Note: Arrays are considered their own types in the semantics of Radon
Why do we need arrays?
The use of arrays is very limited right now
Arrays are useful for storing and manipulating large amounts of data of the same type because it allows for efficient access and manipulation of elements using a simple and consistent syntax. Arrays provide a way to organize data in a structured manner, which makes it easier to write code that performs specific operations on the data, such as searching, sorting, and iterating through the elements.
Memory
In Radon, arrays are stored in contiguous memory locations. The elements of an array are stored in the memory in the order in which they are declared. The first element of the array is stored at the lowest memory address, and the last element of the array is stored at the highest memory address.
The memory layout of an array can be represented as follows:
Memory Address
Memory Address + 1
Memory Address + 2
...
Memory Address + n-1
Each element in the array takes up a certain amount of memory, depending on the data type of the array. For example, an int
which we talked about in Built-in Types; takes up 4 bytes of memory, while a byte
takes up 1 byte of memory. So, an array of 10 ints
would take up 40 bytes of memory (10 x 4 bytes), and an array of 10 bytes
would take up 10 bytes of memory (10 x 1 byte).
Syntax
Declarations
Element assignment
Element access
Unimplemented Features
Cannot iterate through arrays as of right now
Last updated