Skip to content

Commit 1a2b6bd

Browse files
docs: Clarify max_len space calculation (#3641)
1 parent e247502 commit 1a2b6bd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

docs/content/docs/references/space.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,9 @@ pub struct Initialize<'info> {
101101
A few important things to know:
102102

103103
- Don't forget the discriminator when defining `space`
104-
- The `max_len` length represents the length of the structure, not the total
105-
length. (ie: the `max_len` of a Vec\<u32\> will be `max_len` \* 4)
104+
- The `max_len` attribute specifies the maximum number of elements in a Vec, not the total size in bytes.
105+
For example, if you specify `#[max_len(10)]` for a `Vec<u32>`, it means:
106+
- Maximum 10 elements
107+
- Each element (u32) takes 4 bytes
108+
- The Vec itself has a 4-byte length prefix
109+
- Total space = 4 + (10 * 4) = 44 bytes

0 commit comments

Comments
 (0)