0

From the contract below, if the logs get bigger and bigger (let's say it contains 1M items).

The cost for calling set will be increase or not?

I think that the cost for calling when the array size is 10 and 1M should be the same because the operation in set function is not different.

But I am not sure, so that I post this question.

pragma solidity ^0.5.0;

contract Storage {
    struct Log {
        string fname;
        string lname;
        string dob;
    }
    mapping (uint => Log) logs;

    function set(uint memory index, string memory fname, string memory lname, string memory dob) public returns (uint) {
        index++;
        logs[index] = Log(fname, lname, dob);
        return (index);
    }

    function get(uint idx) public view returns (string memory, string memory, string memory) {
        return (logs[idx].fname, logs[idx].lname, logs[idx].dob);
    }
}
1

No, it should will the same regardless of how many items you already have stored in your mapping. Gas costs will only vary depending on the lengths of the strings you're storing.

  • thanks, i think that it will look like this also, but asking to make sure – Alongkorn Chetasumon Mar 26 at 4:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.