solidity에는 delete() 키워드가 있다.
다음과 같이 사용할 수 있다.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
contract MyContract {
uint public number;
uint[] public dynamicArr;
uint[5] public fixedArr;
mapping(uint => uint) public map;
constructor() {
number = 5;
dynamicArr.push(5);
fixedArr[0] = 5;
map[0] = 5;
}
function deleteAll() external {
delete number; // reset value to zero
delete dynamicArr; // reduces size to 0
delete fixedArr; // reset all values to zero
// delete map; // error
delete map[0]; // ok
}
}
uint, uint[], uint[5], mapping 자료구조에 사용한 것을 볼 수 있다.
어떤 자료형에 사용하느냐에 따라서 당연히 적용되는 방식이 다르다.
그러나 핵심은 하나이다.
delete키워드는 삭제가 아닌재설정이다.변수 값을 초기 기본 상태로 재설정할 수 있는 키워드이다.
당연히 초기 기본 상태는 0이다. 마치 free() 함수를 이용해 메모리를 해제하는 것처럼 NULL(0)으로 만드는 것이다.
정수(signed/unsigned)의 경우 변수를 0으로 설정한다.
bool 변수의 경우 변수를 false로 설정한다.
address 변수의 경우 변수를 0(기본값) 주소로 설정한다.
고정 크기 배열 및 바이트의 경우 배열의 각 요소를 기본값으로 설정한다.
동적 배열의 경우 모든 요소를 제거하고 길이를 0으로 설정한다.
구조체의 경우 각 멤버를 기본값으로 설정한다.
solidity에는 delete() 키워드가 있다.
다음과 같이 사용할 수 있다.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
contract MyContract {
uint public number;
uint[] public dynamicArr;
uint[5] public fixedArr;
mapping(uint => uint) public map;
constructor() {
number = 5;
dynamicArr.push(5);
fixedArr[0] = 5;
map[0] = 5;
}
function deleteAll() external {
delete number; // reset value to zero
delete dynamicArr; // reduces size to 0
delete fixedArr; // reset all values to zero
// delete map; // error
delete map[0]; // ok
}
}
uint, uint[], uint[5], mapping 자료구조에 사용한 것을 볼 수 있다.
어떤 자료형에 사용하느냐에 따라서 당연히 적용되는 방식이 다르다.
그러나 핵심은 하나이다.
delete키워드는 삭제가 아닌재설정이다.변수 값을 초기 기본 상태로 재설정할 수 있는 키워드이다.
당연히 초기 기본 상태는 0이다. 마치 free() 함수를 이용해 메모리를 해제하는 것처럼 NULL(0)으로 만드는 것이다.
정수(signed/unsigned)의 경우 변수를 0으로 설정한다.
bool 변수의 경우 변수를 false로 설정한다.
address 변수의 경우 변수를 0(기본값) 주소로 설정한다.
고정 크기 배열 및 바이트의 경우 배열의 각 요소를 기본값으로 설정한다.
동적 배열의 경우 모든 요소를 제거하고 길이를 0으로 설정한다.
구조체의 경우 각 멤버를 기본값으로 설정한다.
Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
Share Dialog
Share Dialog
<100 subscribers
<100 subscribers
No comments yet