You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, memory is allocated always when someone is declaring a struct. Following is an example when someone might not want this behaviour.
struct MyStruct {
uint256 a;
}
function run() {
// fmp: 0x80bytesmemory data;
// fmp: 0x80, data: 0x60
data =abi.encode(1); // allocates 2 words on memory i.e. len and actual data word// fmp: 0xC0, data: 0x80
MyStruct memory v;
// fmp: 0xE0, data: 0x80, v: 0xC0assembly { v :=add(data, 0x20) }
// fmp: 0xE0, data: 0x80, v: 0xA0
}
Motivation
In some cases, the dev knows that a certain memory slice will be always immutable (probably because the original variable will be dropped). However, the struct declaration advances free memory pointer on declaration. If there would be a way to prevent that, it would be great.
Specification
MyStruct memory v = null;
assembly { v :=add(data, 0x20) }
A keyword null can be introduced in Solidity, which would make the struct variable point to 0x00 memory location.
Backwards Compatibility
None to my knowledge.
The text was updated successfully, but these errors were encountered:
Abstract
Currently, memory is allocated always when someone is declaring a struct. Following is an example when someone might not want this behaviour.
Motivation
In some cases, the dev knows that a certain memory slice will be always immutable (probably because the original variable will be dropped). However, the struct declaration advances free memory pointer on declaration. If there would be a way to prevent that, it would be great.
Specification
A keyword
null
can be introduced in Solidity, which would make the struct variable point to0x00
memory location.Backwards Compatibility
None to my knowledge.
The text was updated successfully, but these errors were encountered: