当前位置:网站首页>Mmkv use and principle

Mmkv use and principle

2022-07-07 14:22:00 LLAiden

Basic use

implementation 'com.tencent:mmkv-static:1.2.9'

MMKV.initialize(this);
MMKV kv = MMKV.defaultMMKV();

\ This is a method of storing data api
From the input parameters of the stored function above, we found that it is actually used key,value Next, let's look at the storage method
 Insert picture description here
This storage method is actually a kind of packaging of the first storage method , But do it with SharedPreferences Basic compatibility in calling methods .

And SharedPreferences Compare

SharedPreferences
- advantage
        1. Android Native support does not require the introduction of additional libraries
        2. The data format is readable -
- shortcoming
        1. The limitation of data format leads to more invalid data
        2. Read and store using traditional IO It takes some time
        3. The data format is limited, and the cost of local update is large

MMKV
- advantage
        1. Use MMAP Mode and file mapping write time are greatly reduced
        2. When local updates are appended to read later Map The mechanism automatically removes the weight
        2. The number of customized data is invalid, and the amount of data is small
- shortcoming
        1. Poor readability
        2. Due to the increasing number of file addresses saved in the way of additional update ( When it reaches a certain amount, it will also be comprehensively updated to clean up duplicate data )

原网站

版权声明
本文为[LLAiden]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130615200273.html