address myaddress="0x........."
mapping(address=>uint) map;

Does mapping has the limit? When use mapping, how to free space about the mapping.

  1. In solidity, getFilterChanges function could get the event, but it only receive the event log once, how to know the event happens twice?

Keys for mapping are hashed to derive the storage address, so the limit to a mapping is the logical space addressable by the key type. All mapping slots are implied to be pre-initialized to 0 (or the equivalent of the type being mapped to). This means, in your example you can read and write to any address in the address space. You can delete an element with the delete keyword however if a mapping element is a type that itself contains a mapping (say in a struct), deleting the element will not delete the data in the struct's mapping member.

delete map[myaddress]

Solidity and contracts in general have no access to Events. I think getFilterChanges must be from some external API you're looking at?

  • 1.delete would cost much gas compare to set the value to initial state. 2. getFilterChanges function could only capture the event message once ,before that and after that getFilterChanges has no changes (could not capture the event message).
    – Jim Green
    Aug 25 '16 at 7:05
  • I would add that, although the OP said "to free space", it does not free space in the usual computer storage sense. Indeed the used / free storage areas are not referenced in an index. On the other hand, although delete is more expensive in gas, I believe it saves storage space on the Ethereum node as the Merkle trie of storage is truncated. The trie is not truncated after setting the storage to 0. Aug 25 '16 at 10:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.