Questions tagged [memory]

Questions related to memory use in Solidity or by nodes

Filter by
Sorted by
Tagged with
1
vote
2answers
32 views

How to initialize an array inside the function and push items into it?

How to initialize an array inside the function and push items into it? I'm not gonna initialize outside the function. Here's my code: function tokenOfOwner(address owner) public virtual returns (...
0
votes
1answer
20 views

What is the "bytes memory" in (bool success, bytes memory) = some_address.call{value: some_amount}("")

I understand that the success tells if the receive/fallback methods returned successfully but what does the memory give?
0
votes
2answers
32 views

What is the disadvantage of allocating a new memory array as a way to dynamically increase its size in Solidity?

Since dynamically increasing in-memory arrays is not allowed in Solidity, I thought about creating a helper method like the below to create a new array with one more element every time I wanted to ...
1
vote
1answer
31 views

When to use memory and when not to use?

I watched this video and he uses memory a lot like function verify(address _signer, string memory _message, bytes memory _sig. Why so? Could the function work without using memory? While the usual ...
0
votes
1answer
21 views

How to convert between uint256[] and uint256[x]

Basically, I want to call a function myfunct(uint256[] memory) but I have a uint256[13] I have the uint256[13] because I want to temporarily store uint256s in a function, and save memory--not do ...
0
votes
1answer
11 views

Gas costs of multiple Writes / Reads to same slot in transaction

I know that the EVM wants to charge for reading from slots, and even more for writing to those slots. That all makes sense. My question is, whether the EVM is smart enough to store in memory the ...
1
vote
2answers
126 views

Are storage values copied or referenced?

Given this contract contract C { struct Product { uint price } Product[] storage products; function doSomething() { products.push(Product({price: 100})); products.push(...
1
vote
1answer
36 views

Weird behavior when dealing with uint32 memory array in Yul

There's something I can't understand in the way Solidity handles dynamic-size memory arrays. For instance, let us consider the following contract: pragma solidity ^0.8.0; ...
1
vote
1answer
42 views

Can you use a local `storage` value after it is deleted from a mapping or array?

In Solidity, if you delete a value from a mapping or shorten an array, are local storage references to the deleted item still valid? Case 1: contract Case1 { mapping(uint256 => Widget) private ...
1
vote
1answer
41 views

Why do you have to specify calldata or memory for complex types?

Why do you have to specify calldata or memory for complex types like (string, array, struct etc)?
1
vote
1answer
52 views

What is the layout of returndata from returndatacopy opcode?

I am attempting to perform operations on returned data from delegatecall opcode using a similar familiar proxy pattern: assembly { let ptr := mload(0x40) // load empty memory address pointer ...
0
votes
1answer
14 views

default storage location

This post (When should I use calldata and when should I use memory?) explains the differences between calldata and memory. However where are function arguments or variables within functions stored if ...
0
votes
1answer
32 views

Initialising an array with a single value in solidity

I want to create an array of all 1's. As per my understanding, doing it manually after declaration through a for loop will lead to high gas expense. So, is there any way to initialize an array at once,...
0
votes
1answer
15 views

Dynamic memory management in contracts

After reading a ton of solidity and ethereum documentation and following a course about writing ethereum contracts, a question has arised. This is: When a contract is deployed to the blockchain, it ...
0
votes
0answers
19 views

How do I use memory?

I am learning solidity, and are trying to get "totalBuyFee" to be constantly reducing each time the function "greenwallbuyfee" is called. Do you guys know how I can retrieve the ...
0
votes
0answers
15 views

Reset array require an additional "(0)"

I'm writing a contract where I need to reset an array (contract attribute) to an empty array: pragma solidity >=0.6.0; contract MyCon { address[] public arr; function test() ...
4
votes
2answers
268 views

Why does Solidity never free memory?

I was reading Solidity's Layout in Memory docs, and I was rather surprised to learn that: Solidity always places new objects at the free memory pointer and memory is never freed (this might change in ...
1
vote
1answer
49 views

Understanding why this blob of assembly code adds 0x20 and 0x1f [duplicate]

The execute function defined in MakerDAO's DSProxy contains this blob of assembly code: assembly { let succeeded := delegatecall(sub(gas, 5000), _target, add(_data, 0x20), mload(_data), 0, 0) ...
1
vote
1answer
30 views

Does data in memory variables get added to the blockchain? How does consensus work for memory?

If a function call involves a memory variable, does the data in memory get added to the blockchain history? If no, how come others can validate the transaction? Is the data only deleted after a block ...
1
vote
1answer
46 views

Where are value-type function arguments stored in Solidity?

When we define a function, say test(uint256 val). I would presume val would be implicitly defined in memory. But what if we change the funtion visibility modifier, does that change the location of ...
0
votes
1answer
26 views

Data location memory or calldata [duplicate]

Can someone tell me how to solve this problem? I am not advanced and cannot figure it out.
0
votes
1answer
28 views

Using storage for local function variables

In one function, I was forced to declare a variable with the memory type storage (since there is mapping inside the struct). Is it much more expensive than memory? And how justified is it if I will ...
1
vote
0answers
200 views

Converting static variable to memory

I have the following code snippet in my contract, trying to call flashLoan from Aave. address private constant LINK = 0x...; function myFlashLoanCall(uint256 _amount, bytes memory _params) public {...
1
vote
1answer
30 views

Why 1225312 is the last addressable location in memory?

I was dabbling with inline assembly, and I wanted to discover the extent of addressable memory. After many trials, I found out that the only usable memory locations that could be accessed with OPCODEs ...
0
votes
0answers
17 views

Invalid string crashes Remix IDE

If I have an empty function that accepts a string memory input, and if I pass invalid strings like: " "a """ the Remix IDE crashes. Is this just an issue with Remix? If not, ...
0
votes
0answers
26 views

Is it possible to get HMM (Heterogeneous Memory Management) to work with GPU's mining Ethereum? Trying to use low memory cards

Many GPU's are capable of doing the computing for Eth, but they lack the GPU memory to actually hold the DAG file. It seems like HMM (Heterogeneous Memory Management) may be able to resolve this issue,...
1
vote
0answers
21 views

How to give an array in storage value from an array from a function's input parameters

Below is the code that I have: struct Cow{ uint age; uint name; } Cow[] cows; // this is the code I am trying below. function createCows(Cow[] memory _cows) public { cows =_cows; } When ...
1
vote
1answer
89 views

Data location specification and bytes32

Why is data location not required to be specified for bytes32?
1
vote
0answers
39 views

Saving String Memory Argument to Struct Array

I have the following Solidity code that compiles and tests okay, but the insurancePlan property of the Patient struct is not being saved. I've tried many variations and it is just blank (empty) when I ...
0
votes
1answer
233 views

If I pass an enum as a parameter does it get stored in the blockchain?

I'm developing a Rock/Paper/Scissors Smart Contract (with a Commit-Reveal scheme). I have this enum: enum Move {rock, paper, scissors} I want to pass it to a function, without storing it to the ...
0
votes
0answers
22 views

Why do you always have to declare the "memory" keyword for strings inside a function? [duplicate]

Example: function myfunc (string memory words) public returns (string memory) { XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX } Why is it compulsory to declare the "memory" keyword? Would the ...
0
votes
0answers
79 views

How store memory array in storage

In this code, I want to send an array of bytes32 and store them in the struct but I get the error which is TypeError: Type string memory[8] memory is not implicitly convertible to expected type ...
3
votes
1answer
572 views

In solidity, how to copy a string or pass it by value?

In this example I only modify string a, but both a and b are changed. It seems like the string wasn't copied. I only want to change a. How do you copy a string and how do you pass a string by value to ...
1
vote
0answers
61 views

Private Ethereum PoA error: "out of memory"

I'm working with multi node setup on Ethereum private chain PoA. We have all three validator nodes. blockchain ├── genesis.json ├── node1 │ ├── geth │ ├── keystore │ ├── ...
0
votes
1answer
16 views

Why did I get an error about using memory keyword in function getname?

// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; contract s12 { uint public age; string public name; bool rollno; constructor() public { rollno= false; } ...
0
votes
1answer
184 views

How to returns fixed length array in solidity

I get the following error, how to resolve it? Expected type name function Array_Data () public view returns (memory uint []) {^ ---- ^. pragma solidity >=0.5.0 <0.6.0; contract Lock { uint[...
1
vote
0answers
232 views

What is the default cache value of Geth?

According to the help page of Geth, --cache value defines Megabytes of memory allocated to internal caching (default = 4096 mainnet full node, 128 light mode) (default: 1024) I don't quite get it, is ...
2
votes
0answers
142 views

How to store array parameter of a function to contract state?

I am trying to save an invoice to contract storage (see function addNewInvoice(..)) but I seem to be tripping over the data locations. // SPDX-License-Identifier: private pragma solidity >=0.7.0; ...
2
votes
1answer
385 views

Clarification on how Calldata persists on the blockchain and how Optimistic Rollups use it

So I see that a lot of optimistic rollup solutions say that they store the chain's transaction data on Ethereum via "calldata" which is way cheaper in gas costs than contract storage (I ...
2
votes
1answer
1k views

Type struct Mycontract.User memory is not implicitly convertible to expected type struct Mycontract.User storage pointer

pragma solidity >=0.5.0 <0.7.0; contract Mycontract{ uint256 a; struct User { string name; } User[] users; function foo() public{ **User storage user=User("hey&...
0
votes
1answer
33 views

The below code gets compiled but when foo is called invalid opcode error is thrown

pragma solidity >=0.5.0 <0.7.0; contract Mycontract{ uint256 a; struct User { string name; } User[] users; function foo() public{ User storage user=users[0]; ...
0
votes
1answer
31 views

why x(function setArr) is not being returned?

pragma solidity >=0.5.0 <0.7.0; contract Example{ uint256[3] x; function setArr(uint256[3] memory y) public returns(uint256[3] memory){ x=y; return getArr(x); } ...
0
votes
1answer
28 views

Understanding data location

pragma solidity ^0.5.16; contract mycontract{ uint256 public a; function foo(string calldata _name) external { string memory names; names = _name; getname(names); ...
0
votes
1answer
410 views

Explicit type conversion not allowed from "string memory" to "uint256"

I'm using an oracle to get results from a custom api. The result is in string by default. I want to convert it to uint256, so that I can perform basic arithmetic functions. Here's my code: function ...
0
votes
0answers
115 views

Memory Arrays Should Have Push() And Pop()

Dynamic memory arrays currently cannot be resized. This is true for Solang and solc solidity. However, Solang uses a heap, and has a realloc() function. Thus it is is possible for Solang to support ...
3
votes
1answer
1k views

Geth Version: 1.9.12-stable keeps getting killed...Out of memory: Kill process (geth) score 901 or sacrifice child

I am experiencing issues with my Geth (Version: 1.9.12-stable) nodes. Very often Geth exhausts all memory, which causes a sudden drop in blocks, resulting in the node falling behind. I am running ...
0
votes
0answers
21 views

How to save/read mappings within struct?

I am trying to create a mapping inside struct and then create a mapping of the struct. Take a look at below example: // ------------------------------------------------------------------------ ...
1
vote
1answer
124 views

TypeError: Member "editor" not found or not visible after argument-dependent lookup in struct PrivateSmartContract.BuildingRental storage ref

I want to store user's wallet address array as editor's address so i created struct with array like following pragma solidity >=0.4.0 <0.7.0; pragma experimental ABIEncoderV2; contract ...
0
votes
1answer
279 views

ERC20 decimals and gas costs

This question is twofold: The standard number of decimals for an ERC20 token is 18. If we lower this number, can we expect decreased gas costs when creating/transferring the token, since this should ...
4
votes
2answers
165 views

Variable Names and Memory

Is there a cut-off where a variable name uses more memory? For instance: uint public priceOfEthYesterday9AMUSAET vs uint public pEth One is more descriptive, but if it's costing me gas I don't ...