- Notifications
You must be signed in to change notification settings - Fork1.9k
An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, POSIX, and OHOS.
License
Tencent/MMKV
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
中文版本请参看这里
MMKV is anefficient,small,easy-to-use mobile key-value storage framework used in the WeChat application. It's currently available onAndroid,iOS/macOS,Windows,POSIX andHarmonyOS NEXT.
Efficient. MMKV uses mmap to keep memory synced with files, and protobuf to encode/decode values, making the most of Android to achieve the best performance.
- Multi-Process concurrency: MMKV supports concurrent read-read and read-write access between processes.
Easy-to-use. You can use MMKV as you go. All changes are saved immediately, no
sync
, noapply
calls needed.Small.
- A handful of files: MMKV contains process locks, encode/decode helpers and mmap logics, and nothing more. It's really tidy.
- About 50K in binary size: MMKV adds about 50K per architecture on App size, and much less when zipped (APK).
Add the following lines tobuild.gradle
on your app module:
dependencies { implementation'com.tencent:mmkv:2.1.0'// replace "2.1.0" with any available version}
Starting from v2.0.0, MMKVno longer supports 32-bit arch and API level 22 or 21, if you want 32-bit or API level 21~22, use v1.3.x LTS series.
For other installation options, seeAndroid Setup.
You can use MMKV as you go. All changes are saved immediately, nosync
, noapply
calls needed.
Setup MMKV on App startup, say yourApplication
class, add these lines:
publicvoidonCreate() {super.onCreate();StringrootDir =MMKV.initialize(this);System.out.println("mmkv root: " +rootDir);//……}
MMKV has a global instance, that can be used directly:
importcom.tencent.mmkv.MMKV;MMKVkv =MMKV.defaultMMKV();kv.encode("bool",true);booleanbValue =kv.decodeBool("bool");kv.encode("int",Integer.MIN_VALUE);intiValue =kv.decodeInt("int");kv.encode("string","Hello from mmkv");Stringstr =kv.decodeString("string");
MMKV also supportsMulti-Process Access. Full tutorials can be found hereAndroid Tutorial.
Writing randomint
for 1000 times, we get this chart:
For more benchmark data, please refer toour benchmark.
Efficient. MMKV uses mmap to keep memory synced with files, and protobuf to encode/decode values, making the most of iOS/macOS to achieve the best performance.
Easy-to-use. You can use MMKV as you go, no configurations are needed. All changes are saved immediately, no
synchronize
calls are needed.Small.
- A handful of files: MMKV contains encode/decode helpers and mmap logics and nothing more. It's really tidy.
- Less than 30K in binary size: MMKV adds less than 30K per architecture on App size, and much less when zipped (IPA).
- InstallCocoaPods;
- Open the terminal,
cd
to your project directory, runpod repo update
to make CocoaPods aware of the latest available MMKV versions; - Edit your Podfile, add
pod 'MMKV'
to your app target; - Run
pod install
; - Open the
.xcworkspace
file generated by CocoaPods; - Add
#import <MMKV/MMKV.h>
to your source file and we are done.
For other installation options, seeiOS/macOS Setup.
You can use MMKV as you go, no configurations are needed. All changes are saved immediately, nosynchronize
calls are needed.Setup MMKV on App startup, in your-[MyApp application: didFinishLaunchingWithOptions:]
, add these lines:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// init MMKV in the main thread [MMKVinitializeMMKV:nil];//...returnYES;}
MMKV has a global instance, that can be used directly:
MMKV *mmkv = [MMKVdefaultMMKV]; [mmkvsetBool:YESforKey:@"bool"];BOOL bValue = [mmkvgetBoolForKey:@"bool"]; [mmkvsetInt32:-1024forKey:@"int32"];int32_t iValue = [mmkvgetInt32ForKey:@"int32"]; [mmkvsetString:@"hello, mmkv"forKey:@"string"];NSString *str = [mmkvgetStringForKey:@"string"];
MMKV also supportsMulti-Process Access. Full tutorials can be foundhere.
Writing randomint
for 10000 times, we get this chart:
For more benchmark data, please refer toour benchmark.
Efficient. MMKV uses mmap to keep memory synced with files, and protobuf to encode/decode values, making the most of Windows to achieve the best performance.
- Multi-Process concurrency: MMKV supports concurrent read-read and read-write access between processes.
Easy-to-use. You can use MMKV as you go. All changes are saved immediately, no
save
, nosync
calls are needed.Small.
- A handful of files: MMKV contains process locks, encode/decode helpers and mmap logics, and nothing more. It's really tidy.
- About 10K in binary size: MMKV adds about 10K on application size, and much less when zipped.
Getting source code from git repository:
git clone https://github.com/Tencent/MMKV.git
Add
Core/core.vcxproj
to your solution;Add
MMKV
project to your project's dependencies;Add
$(OutDir)include
to your project'sC/C++
->General
->Additional Include Directories
;Add
$(OutDir)
to your project'sLinker
->General
->Additional Library Directories
;Add
mmkv.lib
to your project'sLinker
->Input
->Additional Dependencies
;Add
#include <MMKV/MMKV.h>
to your source file and we are done.
note:
- MMKV is compiled with
MT/MTd
runtime by default. If your project usesMD/MDd
, you should change MMKV's setting to match your project's (C/C++
->Code Generation
->Runtime Library
), or vice versa. - MMKV is developed with Visual Studio 2017, change the
Platform Toolset
if you use a different version of Visual Studio.
For other installation options, seeWindows Setup.
You can use MMKV as you go. All changes are saved immediately, nosync
, nosave
calls needed.
Setup MMKV on App startup, say in yourmain()
, add these lines:
#include<MMKV/MMKV.h>intmain() { std::wstring rootDir =getYourAppDocumentDir();MMKV::initializeMMKV(rootDir);//...}
MMKV has a global instance, that can be used directly:
auto mmkv = MMKV::defaultMMKV();mmkv->set(true,"bool");std::cout <<"bool =" << mmkv->getBool("bool") << std::endl;mmkv->set(1024,"int32");std::cout <<"int32 =" << mmkv->getInt32("int32") << std::endl;mmkv->set("Hello, MMKV for Windows","string");std::string result;mmkv->getString("string", result);std::cout <<"string =" << result << std::endl;
MMKV also supportsMulti-Process Access. Full tutorials can be found hereWindows Tutorial.
Efficient. MMKV uses mmap to keep memory synced with files, and protobuf to encode/decode values, making the most of POSIX to achieve the best performance.
- Multi-Process concurrency: MMKV supports concurrent read-read and read-write access between processes.
Easy-to-use. You can use MMKV as you go. All changes are saved immediately, no
save
, nosync
calls are needed.Small.
- A handful of files: MMKV contains process locks, encode/decode helpers and mmap logics, and nothing more. It's really tidy.
- About 7K in binary size: MMKV adds about 7K on application size, and much less when zipped.
Getting source code from the git repository:
git clone https://github.com/Tencent/MMKV.git
Edit your
CMakeLists.txt
, add those lines:add_subdirectory(mmkv/POSIX/src mmkv)target_link_libraries(MyApp mmkv)
Add
#include "MMKV.h"
to your source file and we are done.
For other installation options, seePOSIX Setup.
You can use MMKV as you go. All changes are saved immediately, nosync
, nosave
calls needed.
Setup MMKV on App startup, say in yourmain()
, add these lines:
#include"MMKV.h"intmain() { std::string rootDir =getYourAppDocumentDir();MMKV::initializeMMKV(rootDir);//...}
MMKV has a global instance, that can be used directly:
auto mmkv = MMKV::defaultMMKV();mmkv->set(true,"bool");std::cout <<"bool =" << mmkv->getBool("bool") << std::endl;mmkv->set(1024,"int32");std::cout <<"int32 =" << mmkv->getInt32("int32") << std::endl;mmkv->set("Hello, MMKV for Windows","string");std::string result;mmkv->getString("string", result);std::cout <<"string =" << result << std::endl;
MMKV also supportsMulti-Process Access. Full tutorials can be found herePOSIX Tutorial.
Efficient. MMKV uses mmap to keep memory synced with file, and protobuf to encode/decode values, making the most of native platform to achieve best performance.
- Multi-Process concurrency: MMKV supports concurrent read-read and read-write access between processes.
Easy-to-use. You can use MMKV as you go. All changes are saved immediately, no
sync
, noflush
calls needed.Small.
- A handful of files: MMKV contains process locks, encode/decode helpers and mmap logics and nothing more. It's really tidy.
- About 600K in binary size: MMKV adds about 600K per architecture on App size, and much less when zipped (HAR/HAP).
ohpm install @tencent/mmkv
You can use MMKV as you go. All changes are saved immediately, nosync
, noapply
calls needed.
Setup MMKV on App startup, say yourEntryAbility.onCreate()
function, add these lines:
import{MMKV}from'@tencent/mmkv';exportdefaultclassEntryAbilityextendsUIAbility{onCreate(want:Want,launchParam:AbilityConstant.LaunchParam):void{letappCtx=this.context.getApplicationContext();letmmkvRootDir=MMKV.initialize(appCtx);console.info('mmkv rootDir: ',mmkvRootDir);……}
MMKV has a global instance, that can be used directly:
import{MMKV}from'@tencent/mmkv';letmmkv=MMKV.defaultMMKV();mmkv.encodeBool('bool',true);console.info('bool = ',mmkv.decodeBool('bool'));mmkv.encodeInt32('int32',Math.pow(2,31)-1);console.info('max int32 = ',mmkv.decodeInt32('int32'));mmkv.encodeInt64('int',BigInt(2**63)-BigInt(1));console.info('max int64 = ',mmkv.decodeInt64('int')); letstr:string='Hello OpenHarmony from MMKV';mmkv.encodeString('string',str);console.info('string = ',mmkv.decodeString('string'));letarrayBuffer:ArrayBuffer=StringToArrayBuffer('Hello OpenHarmony from MMKV with bytes');mmkv.encodeBytes('bytes',arrayBuffer);letbytes=mmkv.decodeBytes('bytes');console.info('bytes = ',ArrayBufferToString(bytes));
As you can see, MMKV is quite easy to use.For the full documentation, seeHarmonyOS NEXT Tutorial.
MMKV is published under the BSD 3-Clause license. For details check out theLICENSE.TXT.
Check out theCHANGELOG.md for details of change history.
If you are interested in contributing, check out theCONTRIBUTING.md, also join ourTencent OpenSource Plan.
To give clarity of what is expected of our members, MMKV has adopted the code of conduct defined by the Contributor Covenant, which is widely used. And we think it articulates our values well. For more, check out theCode of Conduct.
Check out theFAQ first. Should there be any questions, don't hesitate to createissues.
User privacy is taken very seriously: MMKV does not obtain, collect or upload any personal information. Please refer to theMMKV SDK Personal Information Protection Rules for details.
About
An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, POSIX, and OHOS.