Calldata vs Memory

Published by Mario Oettler on

Last Updated on 24. March 2025 by Mario Oettler

If you are unaware of what calldata, memory and storage is, you an take a look here.

Calldata is an immutable, temporary location for function arguments.

Here is a code sample to demonstrate the difference in gas cost.

pragma solidity 0.8.29;

contract CallData{
    function callData(uint256[] calldata varA) public{

    }

    function memoryData(uint256[] memory varB) public{

    }
}
OperatorGas Costs
callData448
memory1541

It is important to notice that calldata is immutable. Hence, it is impossible to alter values. The following code results in a compiler error as the member push() is not available for calldata.

    function callData(uint256[] calldata varA) public returns(uint256[] calldata){
        varA.push() = 5;
        return varA;
    }

Categories:

https://blockchain-academy.hs-mittweida.de/wp-content/uploads/2021/04/logo_bcam_rgb_gross.png

Welcome

Blockchain Academy

Continue with credential

No account yet?

Powered by Hidy

Register with Hidy


Register
Sign in

We need the following credential to register:

please select:

To create a new account, we need the following data from you:

We would appreciate the following additional information from you for the creation of your account:

Welcome

Blockchain Academy

Continue with credential

Already have an account?

Powered by Hidy

Sign in with Hidy


Register
Sign in

We need the following credential to log in:

please select: