Code has been added to clipboard!

Memory Stored Reference Types

Example
pragma solidity ^0.4.0;

contract cont {
    uint[] x; // data of x is located inside storage

    // data of memoryArray is located inside memory
    function func1(uint[] memoryArray) {
        x = memoryArray; // works, copies the whole array into storage
        var y = x; // works, assigns a pointer, y's data location is storage
        y[7]; // fine, will return the 8th element
        y.length = 2; // fine, will modify x through y
        delete x; // fine, will clear the array and modify y
        // The following line of code does not work, since it would need to create a temporary
        // unnamed array inside of the storage, however, storage is allocated "statically":
        // y = memoryArray;
        // The following line of Soidity code will not work either, since it would "reset" the pointer, but there
        // but there is no viable location it could point to.
        // delete y;
        func2(x); // calls func2, thus handing over the reference to x
        func3(x); // calls func3, creates an independent, temporary duplicate in memory
    }

    function func2(uint[] storage storageArray) internal {}
    function func3(uint[] memoryArray) {}
}