Questions tagged [memory]

Questions related to memory use in Solidity or by nodes

Filter by
Sorted by
Tagged with
0
votes
1answer
9 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
11 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
8 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
57 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
28 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
24 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
17 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
14 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
25 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
14 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
25 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
13 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
14 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
15 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
43 views

Data location specification and bytes32

Why is data location not required to be specified for bytes32?
1
vote
0answers
34 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
98 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
20 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
37 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
319 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
58 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
12 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
89 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
148 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
53 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; ...
0
votes
0answers
47 views

Storage vs Memory in the context of Gas Cost

I have two snippets -- one using memory, the other referencing storage: function winnerName() public view returns (string memory winnerName_) { string memory winnerName_ = ...
0
votes
1answer
200 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
640 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
29 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
28 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
26 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
242 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
60 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
849 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
16 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
94 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
202 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 ...
3
votes
2answers
87 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 ...
2
votes
1answer
305 views

Why use anything but uint256/int256 outside of a struct?

I see how uint8 can save space within a struct, but outside of that I do not see any reason to use anything but uint256. The gas cost is slightly higher for uint8. The only reason I can think of is ...
0
votes
1answer
26 views

Deleting vs. Assigning to Default Values

If I have a struct with many customer accounts: bytes32[] public customerID; mapping(bytes32 => CustomerAccounts) public customerAccounts; struct CustomerAccounts{ address customer; uint ...
2
votes
1answer
1k views

Efficient Bit Packing

I have a struct with the following variables: struct contract { address customer; uint8 tokentype; // 5 token types uint8 size; // 5 sizes bool gender; // 2 types ...
0
votes
1answer
23 views

Memory Efficiency of Constant Variables

Say I have a contract with several functions that apply various particular constants. circumference = 628318 * radius / 1e5; dividend = balance * 123 / 1e4; It would be easier for readers to ...
0
votes
1answer
22 views

Modify the state using returned variable (Array.push)

In my contact I want to have one place where I find an existing object(struct) and then use it in multiple places to read and modify it - but seems like it's not possible? contract A { struct ...
49
votes
1answer
13k views

When should I use calldata and when should I use memory?

I have seen people use both memory and calldata keywords when writing Solidity. Specifically, they are used when declaring function parameters. When should I use memory and when should I use calldata?...
0
votes
1answer
40 views

What is the meaning of "memory is erased between (external) function calls"?

From the official documentation on the memory keyword: The second is “memory”, this is used to hold temporary values. It is erased between (external) function calls and is cheaper to use. Can ...
3
votes
1answer
556 views

How do mappings in solidity occupy memory

Say, I declare a mapping that uses uint256 numbers as keys and maps them to a single 8 bit character. I add 5 members to this mapping. Obviously, I can then access any of these 5 characters using ...
0
votes
1answer
46 views

What does this mean: "It is not possible to enumerate storage from within a contract" (Solidity doc)?

In the Solidity docs section on memory, you find this paragraph (emphasis added): Each account has a data area called storage, which is persistent between function calls and transactions. Storage ...
0
votes
1answer
74 views

Expected ')' but got identifier if(string name != users[name]){ ^--^

pragma solidity >=0.4.0 <0.7.0; contract NewHello{ mapping(address => string) public users; // contains a name for every address function updateUser(string memory name) public { ...
0
votes
1answer
1k views

member not found or not visible after argument-dependent lookup in mapping

pragma solidity >=0.4.0 <0.7.0; contract New{ mapping(address => string) public users; string name; address[] public userAddress ; //string[] public userNames; ...
2
votes
2answers
307 views

Where is the length of an array located in terms of memory layout?

For example, given the following cases: uint[3] memory arr; uint[] memory arr = new uint[](3); Suppose I try to access arr from within an assembly block (using mload, for example). Where (...