Skip to content

Commit 6731373

Browse files
committed
add example of the internal structures of array types
1 parent b3898e3 commit 6731373

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

content/posts/odin-guide.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,32 @@ types of arrays:
423423
| dynamic array | `[dynamic]T` |
424424
| dynamic array (fixed capacity) | `[dynamic;N]T` |
425425

426+
internal structure of array types inside `base/runtime/core.odin`:
427+
```odin
428+
// static array
429+
// just a linear strip of raw data
430+
431+
// slice
432+
struct {
433+
data: rawptr, // just a pointer, no actual data
434+
len: int,
435+
}
436+
437+
// dynamic array
438+
struct {
439+
data: rawptr, // just a pointer, no actual data
440+
len: int,
441+
cap: int,
442+
allocator: Allocator,
443+
}
444+
445+
// fixed capacity dynamic array
446+
struct {
447+
data: [capacity]T, // holds the actual raw data
448+
len: int,
449+
}
450+
```
451+
426452
static arrays:
427453
```odin
428454
// basic usage

0 commit comments

Comments
 (0)