1

I can think of two ways:

1) Allocate a 2D array:

uint256 public W = 15;
uint256 public H = 15;
uint256[W][H] public grid;

2) Use mapping:

mapping (uint8) => mapping(uint8 => uint256)) public grid;

(I'm asking about if we can use tuple as key in this question: Tuple as mapping key?)

Q: What are the aspects to compare? I can think of transaction fees (and maybe speed).

Q: How do we compare the two?

Q: Is there another (better) way?

Regarding transaction fee, I don't know much about how contracts exactly work in Ethereum yet, but my guess is that the fixed 2D array is more expensive at the beginning since it has to write the whole array into the block. Not sure if mapping is more expensive when both are near full.

  • I would like to know too, anyone? Say I have 2D array with width and height, I want to have a mapping of the altitudes of each grid. – Richard Fu Aug 1 '18 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.