Skip to content

Commit

Permalink
Merge pull request #1372 from michaelkirk/patch-1
Browse files Browse the repository at this point in the history
prefer `length` over `size` when talking about number of elements vs. bytesize
  • Loading branch information
marioidival authored Aug 26, 2020
2 parents 9477098 + f245c1c commit 19f0a03
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/primitives/array.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Arrays and Slices

An array is a collection of objects of the same type `T`, stored in contiguous
memory. Arrays are created using brackets `[]`, and their size, which is known
at compile time, is part of their type signature `[T; size]`.
memory. Arrays are created using brackets `[]`, and their length, which is known
at compile time, is part of their type signature `[T; length]`.

Slices are similar to arrays, but their size is not known at compile time.
Slices are similar to arrays, but their length is not known at compile time.
Instead, a slice is a two-word object, the first word is a pointer to the data,
and the second word is the length of the slice. The word size is the same as
usize, determined by the processor architecture eg 64 bits on an x86-64.
Expand All @@ -31,8 +31,8 @@ fn main() {
println!("first element of the array: {}", xs[0]);
println!("second element of the array: {}", xs[1]);
// `len` returns the size of the array
println!("array size: {}", xs.len());
// `len` returns the count of elements in the array
println!("number of elements in array: {}", xs.len());
// Arrays are stack allocated
println!("array occupies {} bytes", mem::size_of_val(&xs));
Expand Down

0 comments on commit 19f0a03

Please sign in to comment.