So, in an ordinary programming language, we have stack and heap.

Reference types such as array gets stored in heap. and the variable which holds the address(pointer) of this array is stored in stack..

Question 1) what about solidity's memory ? when array gets created in memory, does solidity store the pointer of that array in stack ?

Question 2) what about solidity's storage ? I think in this case, since it's persisent, stack doesn't come into play. so where is the pointer of the array(stored in storage) stored ?

  • Reference types such as array gets stored in heap - that's wrong. Only dynamic arrays are typically stored on the heap, and even that fact is implementation-dependent and not dictated by the language standard (i.e., whoever implements a compiler can do whatever they choose). – goodvibration Oct 2 '20 at 14:53
  • As to the first question, the answer is probably yes (though again, that's an implementation-based decision). – goodvibration Oct 2 '20 at 14:55
  • As to the second question, whenever you refer to a storage construct, the pointer to it is most likely maintained on the stack (and again - depending on the decision made by the author of the compiler). – goodvibration Oct 2 '20 at 14:56
  • The EVM is stack based environment so most operation go through it. Passing parameters to functions is done through the stack. From my tests: 1/ Value types are passed as they are, 2/ Memory types are passed as a pointer to memory, 3/ Storage types are passed as storage slot (mappings are more complex so they may pass extra data but I'm not sure). I don't know if that is standard or it will change in the future. For example if approved EIP 615 will introduce subroutines. – Ismael Oct 4 '20 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.