瀏覽代碼

docs: Clarify `max_len` space calculation (#3641)

Bob 6 月之前
父節點
當前提交
1a2b6bd65a
共有 1 個文件被更改,包括 6 次插入2 次删除
  1. 6 2
      docs/content/docs/references/space.mdx

+ 6 - 2
docs/content/docs/references/space.mdx

@@ -101,5 +101,9 @@ pub struct Initialize<'info> {
 A few important things to know:
 
 - Don't forget the discriminator when defining `space`
-- The `max_len` length represents the length of the structure, not the total
-  length. (ie: the `max_len` of a Vec\<u32\> will be `max_len` \* 4)
+- The `max_len` attribute specifies the maximum number of elements in a Vec, not the total size in bytes. 
+  For example, if you specify `#[max_len(10)]` for a `Vec<u32>`, it means:
+  - Maximum 10 elements
+  - Each element (u32) takes 4 bytes
+  - The Vec itself has a 4-byte length prefix
+  - Total space = 4 + (10 * 4) = 44 bytes