EatTheBlocks Forum

Memory vs calldata

I have been trying to understand when to use calldata and memory in function arguments . I know calldata is used with external and internal functions and memory is used with public functions.

But I don’t understand when to use any ,I have seen many examples still cant get over it .

I came to know about an error from remix online editor “Data location can only be specified for array,struct or mapping but memory/calldata was given”.
But in this example https://solidity.readthedocs.io/en/v0.6.3/solidity-by-example.html#the-full-contract ,memory is used with bytes

I think you give the answer in your question :slight_smile:

 I know calldata is used with external and internal functions and memory is used with public functions

calldata or memory are used for non-scalar data types, i.e anything that is a container for multiple other values, which is the case of array, mapping, struct … and bytes.