I read somewhere that if you create a storage variable inside a function, it could overwrite another existing one in the global scope of the smart contract, is that true?
So, if I wanted to create a new struct variable inside a function, and then push it to an array, should I create it in the storage space or memory space?
Like this:
MyStruct storage newStruct;
... // modifiying newStruct variables
myStructsArray.push(newStruct);
Or like this:
MyStruct memory newStruct;
... // modifiying newStruct variables
myStructsArray.push(newStruct);
Same question for when wanting to add a newly instantiated struct to a mapping:
MyStruct storage/memory newStruct;
...
MyStructMapping[index] = newStruct;