Learn Solidity (0.5) - Array

preview_player
Показать описание
Learn how to use arrays in Solidity.

Рекомендации по теме
Комментарии
Автор

wow!! thanks so much for your video's!! Have been searching like crazy to get some answers (newbie) and you answered all my questions about mapping and arrays in 2 of your video's.
Thanks so much!

grndpatoken
Автор

Awesome video 🤩 thanks !!! Question on push ? Is it designed to push single value one at time? In pratical case, can you push multiple values the same time?

salem
Автор

Isn't this remove function taking much more gas than simple delete at specific index? This array shrinking is not very cost effective I guess.

ДаниелДианов
Автор

very similar to javascript even loops in the previous video witch is the exact same thing is very helpful

iyariurrestarazu
Автор

It's funny how in the case when you remove the last element of the array, it copies the last element to the last element, which is redundant.
The newer version of Remix has a gas estimator,
So I wrote a version that did a check to see if the index is the last element and only copy if that is not the case;

function remove(uint index) public {
uint lastIndex = myArray.length - 1;
if (index != lastIndex) {
myArray[index] = myArray[lastIndex];
}
myArray.pop();
}

And the compiler told me it estimates 49531 gas versus 49495 gas, so I guess it's not worth it!

Then I tried doing it without the local variable lastIndex, running the myArray.length -1 computation twice; now it costs 50332 gas.

MrCoreyTexas