vnprc on Nostr: Digging a little deeper to understand this. Apparently, if my LLM is to be trusted, ...
Digging a little deeper to understand this. Apparently, if my LLM is to be trusted, you need to index arrays with usize because they can be stored either on the stack or the heap and need to behave consistently across CPU architectures.
I didn't realize that arrays could go on the heap, but it seems this is what happens when you instantiate an array with Box, Vec, Rc, or Arc.
```
Box::new([1, 2, 3, 4, 5])
vec![1, 2, 3, 4, 5]
Rc::from([1, 2, 3, 4, 5])
Arc::from([1, 2, 3, 4, 5])
```
If only they could make the instantiation code more uniform...😅
Published at
2025-01-16 13:39:02Event JSON
{
"id": "44c7fd45d4c43c0ee3a9ae43f069aab4e046d8acdb65b59fcaed1f92f89237e1",
"pubkey": "d3052ca3e3d523b1ec80671eb1bba0517a2f522e195778dc83dd03a8d84a170e",
"created_at": 1737034742,
"kind": 1,
"tags": [
[
"e",
"e3a1db0a43887333cb004eb71ee156e5c571b532c26c0fe9f69358b3376000dc",
"wss://ditto.pub/relay",
"root",
"d3052ca3e3d523b1ec80671eb1bba0517a2f522e195778dc83dd03a8d84a170e"
],
[
"e",
"c82577dc2b795ce9a521be6a3eb76d8086fc509e396470fb3cedceadc8fc383f",
"wss://ditto.pub/relay",
"reply",
"d3052ca3e3d523b1ec80671eb1bba0517a2f522e195778dc83dd03a8d84a170e"
],
[
"p",
"ccaa58e37c99c85bc5e754028a718bd46485e5d3cb3345691ecab83c755d48cc",
"wss://ditto.pub/relay"
]
],
"content": "Digging a little deeper to understand this. Apparently, if my LLM is to be trusted, you need to index arrays with usize because they can be stored either on the stack or the heap and need to behave consistently across CPU architectures.\n\nI didn't realize that arrays could go on the heap, but it seems this is what happens when you instantiate an array with Box, Vec, Rc, or Arc.\n\n```\nBox::new([1, 2, 3, 4, 5])\nvec![1, 2, 3, 4, 5]\nRc::from([1, 2, 3, 4, 5])\nArc::from([1, 2, 3, 4, 5])\n```\n\nIf only they could make the instantiation code more uniform...😅",
"sig": "96efd89b6b8e222952a2b496a8204b05d41b24e5e1443cdf11c867bd52d58b24fa5e63acc42b55e8757ce741cbfdea5fe8ce4db8b1ab6b89f7a04233d4452fc5"
}