Questions tagged [memory]

Questions related to memory use in Solidity or by nodes

Filter by
Sorted by
Tagged with
35
votes
1answer
16k views

What does the keyword “memory” do exactly?

I've been looking through the code of Etherdice and noticed that some variables are declared like ParserResult memory result; and I haven't found the keyword "memory" in any documentation. What I ...
34
votes
3answers
9k views

Difference between Memory and Storage?

What is the difference between Memory and Storage ? From both the EVM point of view and the contract design one. Thanks!
25
votes
4answers
8k views

How to store IPFS hash using bytes?

Following Q/A (What datatype should I use for an IPFS address hash?) recommend us to use bytes to store IPFS hash. I was using following example(https://github.com/AdrianClv/ethereum-ipfs/blob/master/...
25
votes
2answers
10k views

Can I save structs in a Mapping?

Is it possible to store structs in a Mapping or any dynamic memory structure in my Solidity SmartContract?
14
votes
2answers
12k views

TypeError: Data location must be “storage” or “memory” for parameter in function, but none was given

/// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param ...
13
votes
3answers
5k views

How to run geth at 512Mb RAM Digital Ocean droplet?

When geth process consumes too much memory it gets killed (not at all gracefully) by Digital Ocean. Partly solved the problem by implementing swap - Setting up geth Ethereum node to run ...
13
votes
2answers
2k views

error: Storage location can only be given for array or struct types

Getting the error "Storage location can only be given for array or struct types" in a setup function. The exact line is uint memory _total = 0; I'm confused by the error, because I'm not trying to ...
11
votes
1answer
2k views

Does “delete” on mapping really frees the memory space?

I have the following mapping(uint => Foo[]) data structure. I have mapped 10 unique ids with 10 Foo structs, where each Foo is an arraylist of 10 items. Step 1: for(int i = 0; i < 10; i++) ...
8
votes
1answer
877 views

What is the composition of the blockchain database?

From axic's explanation of the structure of the ethereum database, we learned that data is stored in Merkle Patricia tries, usually inside a LevelDB store. It consists of structures such as blocks, ...
7
votes
2answers
6k views

How to initialize an empty array inside a struct?

Is there a mistake in the way I initialize Bar b in the function foobar? contract Foo { struct Bar { address owner; uint[] x; } Bar[] public bars; function foobar(...
7
votes
2answers
4k views

How to fill dynamic in-memory array

For some reason solidity doesn't allow to push values into memory array Member "push" is not available in bytes32[] memory outside of storage. Here is sample contract code: pragma solidity ^0.4....
6
votes
1answer
310 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?...
6
votes
1answer
2k views

Is it possible to decrease RAM usage of go-ethereum(geth)?

I have a slow computer, which has 2GB memory RAM. One geth app uses %60 percent of the RAM, which lead me to run only one geth node; I cannot run 2 geth nodes in parallel due to RAM overload. [Q] Is ...
6
votes
1answer
335 views

How does dynamic array memory reallocating work?

Let's say I have a dynamic array of some length and I want to push a new element, but memory after last elem is already used. What would happen in such case? Compiler would find a new 'chunk' of ...
6
votes
1answer
234 views

Could more than one mapping's key point to the same memory space?

Since memory is already allocated on (array[0] = value;), I just want to change its pointing key value. Such as array[1] will allow me to access value now. Is it possible to change the key of ...
5
votes
2answers
611 views

Stack too deep | Use memory array to store many “local” variables?

I have a contract that's doing a fairly complex calculation with some intermediate calculations, and I'm running into the "stack too deep" problem. I've tried to use a memory array within the ...
5
votes
3answers
280 views

Why memory arrays are unresizable?

I don't know the required length of my array before execution of the function.. why technically can't I resize my memory array? What is the common way to go around of this problem, if you are also ...
5
votes
1answer
1k views

In solidity, how can I hardcode bytes > 32 bytes

I want to create a contract with a hardcoded bytes variable. contract Test(){ function Test(){ bytes x = 0x..... //greater than 32 bytes } } The above returns a Type int_const not ...
4
votes
2answers
6k views

The difference between contract address and wallet address

Disclaimer: this is a rather long question. To my understanding, contract address and wallet address are two profoundly different concepts, with the only thing in common being the fact that they are ...
4
votes
2answers
309 views

How to pop from (decrease the length of) a memory array in Solidity

I have a function that gets an address array from another contract, conditionally deletes the msg.sender from the array, then saves the new array back to that contract. Because the array backerList ...
4
votes
2answers
1k views

Invalid array length, expected integer literal

I'm trying to declare an in-memory array with a fixed length: uint length = 10; uint[length] memory priorityList; However, it just displays this error message: Invalid array length, expected ...
4
votes
1answer
102 views

What happens when memory is full in a node?

I am using go-ethereum and running a private blockchain network. I want to what is supposed to happen when the memory is full in the nodes. Will the program stop abruptly or will the old blocks get ...
4
votes
2answers
1k views

Assigning memory variable to storage variable, what happens?

I'm curious what happens if you try to do the next thing: contract C { Struct S { uint a; uint b; } mapping(address => s) structs; function updateStructs(S ...
4
votes
1answer
762 views

How to return dynamic sized array's original address on the memory of Solidity?

On the following source code, memOffset returns local values such as 96, 128 as the address value. How could I make it return the original address that is located on the memory, is it possible? After ...
4
votes
1answer
707 views

Assigning an array creates a pointer or copies an array? (Solidity)

Here is the code: pragma solidity^0.4.16; contract Test { struct SomeData { address[] users; } address[] nullArray; mapping(uint => SomeData) SomeDataList; function ...
4
votes
1answer
207 views

Is it possible to get an address of a struct in the Library or Contract without using mapping?

[Q] I was wondering is it possible to get an address of a struct on the memory space? Inside initialise() function after the Node object creation, I want to get is address if it is possible. Since ...
4
votes
1answer
339 views

personal.newAccount(“mypassword”) stops the server when i create two accounts consecutively in local privatenet

personal.newAccount("mypassword") stops the server when i try to create two accounts one after the another. personal.unlockAccount(eth.accounts[0],"mypassword"); same happens when I try unlock ...
3
votes
2answers
32 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 ...
3
votes
1answer
398 views

Why does PUSH1 0x60 PUSH1 x40 MSTORE store 0x60 at memory location 0x50 (and not 0x40)?

According to browser solidity, after executing 000 PUSH1 60 002 PUSH1 40 004 MSTORE Memory is: 0x00: 00000000000000000000000000000000 ???????????????? 0x10: 00000000000000000000000000000000 ?????...
3
votes
1answer
82 views

Are balances of all accounts in memory or disk (storage)?

I simulated two contracts that sending balance to another and simply setting value of a variable(var a = 5;). In contrast my expectation, {var a = 5;} contract consumed more gas than the other. In my ...
3
votes
2answers
836 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 ...
3
votes
1answer
206 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 ...
3
votes
1answer
2k views

Restrict CPU/memory usage of geth while syncing

I'm trying to run a geth node and a bitcoin core node on one server. I started with a DigitalOcean droplet with 2 CPU and 2GB memory, but both the geth and bitcoin node would run out of memory. I ...
3
votes
1answer
452 views

Mist 0.8.6 crashing with Couldn't connect to node? See the logs for more

I have updated Ethereum-Wallet to 0.8.6. My accounts were not showing up in Wallet, so I deleted the .ethereum folder (after taking a backup) and restarted Wallet, but now I was unable to run wallet, ...
3
votes
1answer
742 views

Can I reduce the space chaindata takes up?

So the size of my chaindata folder has snowballed to close to 80GB. Is there a way to reduce it or is the only way to delete it and resync geth with --syncmode fast? Thanks!
3
votes
2answers
349 views

convert bytes to uint8[8] using mstore()

I know how to convert bytes to uint8[8] using mload but mstore seemed like it could be more gas efficient. Is something like this possible? function bytesToUintArray(bytes input) returns (uint8[8])) ...
2
votes
2answers
861 views

Is it possible to copy the internal storage of a smart contract to a new contract?

Assume that I want to implement my own version of a suicide contract function with extended functionality. More specifically, I want to copy the internal storage state of the contract to a new ...
2
votes
2answers
121 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 (...
2
votes
1answer
276 views

Always use “memory” for variables created within functions. Bad practice?

Is it bad practice to systematically use the memory keyword for variables declared within a function (other than constructor)?
2
votes
1answer
228 views

Can marking object as 'memory' before pushing in Array save gas?

We have a struct: struct structEx { uint num; } And an array: structEx[] arr; Have a look at this code snippet, which just instantiates the struct and push: function f() public { structEx s =...
2
votes
1answer
629 views

Delete an entry in a mapping

To my understanding, delete x merely sets the value of x to the default value defined for the type of x (which is typically 0 in one way or another). For example: uint x = 1; delete x; // sets x = 0 ...
2
votes
1answer
52 views

Is memory logged in a transaction?

Data in memory during a transaction is deleted when execution stops. This means this information is not stored in the contract state, but is the information that was in memory during the transaction ...
2
votes
1answer
838 views

How to make mining efficient in terms of memory, for a light weight client?

Since mining is resource intensive process, how to make it more efficient for a lightweight client in terms of memory. I am ready for a trade off even it takes more time to mine than what it would ...
2
votes
1answer
57 views

Two ways of assigning a pointer. Is there a difference?

Here's one way to assign a pointer to variable z: function f(uint8[] memoryArray){ var z = memoryArray; } and here's another function f(uint8[] memoryArray){ uint8[] memory z = memoryArray; ...
2
votes
1answer
63 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 ...
2
votes
1answer
403 views

memory keyword in function argument

What does the memory keyword in the argument of a function do? pragma solidity 0.4.24; pragma experimental "ABIEncoderV2"; contract Conditional { struct Condition { address to; bytes4 ...
2
votes
1answer
87 views

Examples of functions limitations?

I coded different functions and didn't find a standard that define crystal clear how many variables you can use (fields, local or as parameters of modifiers inside this function? Do you know a ...
2
votes
1answer
108 views

Why is the cost of memory non-linear, while the cost of storage is linear?

Why is the cost of memory non-linear, while the cost of storage is linear? I wonder why the cost function of memory vs. storage differ? While storage is associated with a constant cost, this is not ...
2
votes
2answers
446 views

How much memory do I need to mine any blocks on my lockal network?

I have linux box with 5Gb of memory: osboxes@osboxes ~/node1 $ free total used free shared buff/cache available Mem: 5176876 158360 3536464 ...
2
votes
1answer
221 views

My disk has only 1 GB free - how can I use the Linux Ethereum Wallet?

I just downloaded the Ethereum Wallet for Debian Linux (I have Ubuntu 16.04). It appears to be downloading a lot of blocks: it now says that there are 3,310,606 blocks, and the number is decreasing. I ...