You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/posts/jai-guide.md
+24-8Lines changed: 24 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -344,14 +344,6 @@ you can get the memory adress of the first element in an array using the `array.
344
344
345
345
Both Static Arrays and Dynamic Arrays are autocasted to Array Views if the array view is a parameter. Because strings are array views with u8, both share the same definition.
346
346
347
-
Arrays in jai are simply a tiny struct that holds the size and location of where the array actually is in memory. so copying an array directly makes an array that points to the same data.
348
-
349
-
You can initialize arrays using the following syntax:
350
-
351
-
```jai
352
-
array: [4]float = float.[10.0, 20.0, 1.4, 10.0];
353
-
```
354
-
355
347
regular arrays:
356
348
```jai
357
349
// simple array
@@ -403,6 +395,30 @@ array: [2][2]int = .[.[1, 0], .[0, 3]]; // initializing a 2D array with inferred
403
395
value: int = array[0][0]; // indexing a 2D array
404
396
```
405
397
398
+
Static arrays actually hold all of their own data, meaning that copying a static array does a full copy.
399
+
Dynamic arrays and array views (slices) are basically just pointers,
400
+
therefore copying them doesnt copy the actual data, therefore they act like reference types.
401
+
This is what each type of array basically is in practice:
0 commit comments