Skip to main content

Questions tagged [memory]

Questions related to memory use in Solidity or by nodes

Filter by
Sorted by
Tagged with
40 votes
3 answers
15k 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!
Hcharlanes's user avatar
  • 1,135
34 votes
7 answers
16k views

How to store IPFS hash using bytes32?

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/...
alper's user avatar
  • 8,394
147 votes
2 answers
67k 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 that take dynamic types like 'structs' or 'arrays'. When ...
Shane Fontaine's user avatar
56 votes
2 answers
26k 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. ...
uberlaufer's user avatar
34 votes
3 answers
41k 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 ...
CryptoScroller's user avatar
26 votes
4 answers
27k 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....
Alex Zhukovskiy's user avatar
18 votes
2 answers
13k 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 ...
Chaos's user avatar
  • 377
8 votes
1 answer
1k 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, ...
MrChico's user avatar
  • 1,786
6 votes
1 answer
3k 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 ...
alper's user avatar
  • 8,394
4 votes
1 answer
587 views

How does this assembly code create a new "memory end"?

From the docs: mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f))) Context: library GetCode { function at(address _addr) public view returns (bytes memory o_code) { ...
Zach_is_my_name's user avatar
4 votes
1 answer
2k 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 ...
Skellomag's user avatar
1 vote
1 answer
12k views

Type error: memory is not implicitly convertible to expected type

I have a function that returns a list of BetProposition smart contracts: function getBetsForMatchup(uint matchupIdentifier) public returns (BetProposition[]) { return bets[matchupIdentifier]; ...
user339946's user avatar
33 votes
3 answers
24k 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?
arodriguezdonaire's user avatar
17 votes
3 answers
20k 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(...
Manan Mehta's user avatar
11 votes
1 answer
3k 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++) ...
alper's user avatar
  • 8,394
6 votes
1 answer
7k views

Where are strings stored in Solidity?

I wonder where strings are stored in Solidity? Especially, where are string literals, function arguments, and variables stored? I recall, I've read that strings cannot be saved to memory, but is ...
Shuzheng's user avatar
  • 1,855
5 votes
1 answer
3k 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 ...
goodvibration's user avatar
4 votes
1 answer
3k 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 ...
goodvibration's user avatar
4 votes
1 answer
1k 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 ...
alper's user avatar
  • 8,394
4 votes
1 answer
4k views

Creating a 2D in-memory array in Solidity

I'm trying to work with 2D in-memory arrays in Solidity, in which the size is not known at compile time. I've noticed that if I define the array size as a constant, then I can use this syntax, which ...
kronosapiens's user avatar
4 votes
1 answer
7k 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 ...
Eric Falkenstein's user avatar
3 votes
1 answer
467 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, ...
Prashant Prabhakar Singh's user avatar
3 votes
1 answer
3k 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 ...
Inigo's user avatar
  • 131
3 votes
1 answer
1k 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 ...
Eric Falkenstein's user avatar
2 votes
0 answers
135 views

Is it possible for a mapping to run out of space?

Can storage mappings in a contract run out of space? Say that mapping was keyed to an address and the value as the following struct: User bytes32 name uint8 age Theoretically, if there was a ...
The Nomad's user avatar
  • 399
2 votes
2 answers
2k views

What is the proper pattern to use a temporary variable and ensure it gets stored?

A contract has a state variable, which is complex. For the example, lets say it is a mapping of structs. Inside a method, I want to access that and store the changes. Like so: contract FooManager { ...
berkes's user avatar
  • 217
1 vote
1 answer
60 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 ...
ratib90486's user avatar
1 vote
1 answer
157 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 ...
Luke Hutchison's user avatar