Skip to content

Commit

Permalink
chore: add disclaimer on array storage
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Jul 16, 2023
1 parent 6a47d12 commit 6f73467
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ch01-02-storing_arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

On Starknet, complex values (e.g., tuples or structs), are stored in a continuous segment starting from the address of the storage variable. There is a 256 field elements limitation to the maximal size of a complex storage value, meaning that to store arrays of more than 255 elements in storage, we would need to split it into segments of size `n <= 255` and store these segments in multiple storage addresses. There is currently no native support for storing arrays in Cairo, so you will need to write your own implementation of the `StorageAccess` trait for the type of array you wish to store.

> Note: While storing arrays in storage is possible, it is not always recommended, as the read and write operations can get very costly. For example, reading an array of size `n` requires `n` storage reads, and writing to an array of size `n` requires `n` storage writes. If you only need to access a single element of the array at a time, it is recommended to use a `LegacyMap` and store the length in another variable instead.
The following example demonstrates how to write a simple implementation of the `StorageAccess` trait for the `Array<felt252>` type, allowing us to store arrays of up to 255 `felt252` elements.

```rust
Expand Down

0 comments on commit 6f73467

Please sign in to comment.