From 6f734675fc4bf9ecafe25f4d891d60c6ae52dfef Mon Sep 17 00:00:00 2001 From: msaug Date: Sun, 16 Jul 2023 16:02:03 +0200 Subject: [PATCH] chore: add disclaimer on array storage --- src/ch01-02-storing_arrays.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ch01-02-storing_arrays.md b/src/ch01-02-storing_arrays.md index ba1b4f76..c08b8aec 100644 --- a/src/ch01-02-storing_arrays.md +++ b/src/ch01-02-storing_arrays.md @@ -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` type, allowing us to store arrays of up to 255 `felt252` elements. ```rust