axmolengine / axmol

Axmol Engine – A Multi-platform Engine for Desktop, XBOX (UWP) and Mobile games. (A fork of Cocos2d-x-4.0)
https://axmol.dev
MIT License
868 stars 195 forks source link

Memory mapped UserDefaults binary file contains multiple entries for same field #940

Closed rh101 closed 1 year ago

rh101 commented 1 year ago
  1. Call UserDefault::getInstance()->setFloatForKey("SettingName", 1); multiple times. The "SettingName" config value will be written the same number of times to the UserDefault.bin memory mapped file.

image

It has nothing to do with the float value, but rather with the way the setStringForKey works. It doesn't check if the key already exists prior to writing it out to the memory mapped file.

It doesn't actually cause any major issue except for constantly increasing the size of the UserDefaults.bin once it gets past each page size (4kbytes per page?). The reason it works fine is because the last value saved to the memory mapped file will always be the one used, so it's not a critical issue.

halx99 commented 1 year ago

It's by designed, once buffer used by entries(include duplicate) archive to curMapSize, will call flush to tidy entries, the duplicate entiries will removed and the map file used size will be decrease.

rh101 commented 1 year ago

Fair enough, then this is a non-issue. Thank you for the clarification on how it works.