Questions tagged [memory]

Questions related to memory use in Solidity or by nodes

Filter by
Sorted by
Tagged with
0
votes
0answers
7 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
13 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
19 views

Data location specification and bytes32

Why is data location not required to be specified for bytes32?
1
vote
0answers
32 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
45 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
14 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
23 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
134 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
55 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
37 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
92 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
30 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
22 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
95 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
283 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
21 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
108 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
22 views

How secure is this memory wallet?

As we know memory wallets more specifically Brainwallet 1.0 is a failed technology. I want to know how secure is this wallet system? It uses blockchain transaction hash and passphrase to calcualte ...
0
votes
0answers
34 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
594 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
76 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
126 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
53 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 ...
1
vote
1answer
192 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
24 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
638 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
22 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
19 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 ...
27
votes
1answer
7k 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
35 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 ...
2
votes
1answer
275 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
38 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
67 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
892 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
234 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 (...
1
vote
1answer
541 views

Solidity: Convert from “bytes memory” to “address”

I'm using solidity 0.5.0 and when i try to compile my contract it's giving me this error Explicit type conversion not allowed from "bytes memory" to "address" my code is this: /// @dev get broker ...
2
votes
1answer
89 views

why a parameter must be “storage” or “memory”?

I am creating a token like this: pragma solidity ^0.5.0; import "../utils/math/SafeMath.sol"; contract ExampleDivisibleNFTs { using SafeMath for uint256; // Percentage of ownership over a ...
1
vote
2answers
71 views

How do programs on the 'Ethereum World Computer' compare to traditional programs or websites?

So this question has been bugging for me for a while and I can't seem to find the answer to it. Context I have been a web developer for many years. When I access a website, any frontend code is run ...
1
vote
0answers
21 views

Calling private function from external - where are referenced type parameters stored in the end?

Let's assume we have something like: contract C { function externalFunction(uint256[] calldata data) external { privateFunction(data); } function privateFunction(uint256[] memory data)...
1
vote
2answers
2k views

how does Storing and Fetching data works in Smart contracts [closed]

Please help me out with these questions. 1)Where does the contract stores the data? 2)when we access the value of a variable form of a contract, how does it retrieve the latest value? 3)how is the ...
0
votes
1answer
287 views

error: data location must be storage or memory for parameter in funtion but none was given solidity [duplicate]

pragma solidity ^0.5.0; contract Election{ //model a candidates struct candidate { uint id; string name; uint votecount; } //store candidates //fetch candidate mapping(uint =...
6
votes
2answers
3k views

How much data can I store in a smart contract, what is the cost and how it is implemented?

If I suppose I use a smart contract as a database, how much data can I store? speaking only of strings and integers, save them in contract data structures does it cost in addition to the gas used for ...
0
votes
1answer
48 views

Cannot retrieve data from smartcontract during tests

I am writing truffle tests for my smart contract solidity version 0.4.24. The tests are emitting events to write data to memory through smart contract. But I am unable to retrieve data from functions. ...
3
votes
1answer
663 views

Switching from 'storage' to 'memory' increases the gas-cost

I've read several related answers and blog posts, all of them suggesting that for the sake of reading complex state variables (i.e., arrays and structures), one should always prefer declaring the ...
1
vote
2answers
349 views

How could Solidity 0.5.0 dynamic sized parameters be declared as storage?

As I understand it 'memory' in the EVM is a byte array and cannot be dynamically resized, whereas 'storage' is able to be resized. What is happening when a parameter is declared as storage. Where is ...
0
votes
0answers
986 views

FATAL ERROR: Rebalance Allocation failed - process out of memory

So while running truffle compile for my contracts on AWS Ubuntu server I got the following error: <--- Last few GCs ---> [17055:0x3985730] 11958 ms: Scavenge 511.7 (553.4) -> 506.9 (553.4) ...