IOS工程师面试被问到的问题SQLite store takes a "long time" to save怎么解决?
2012-11-02 19:38
417 查看
官方文档的描述和回答:
Problem: You are using an SQLite store and notice that it takeslonger to save to the SQLite store than it does to save the same data to an XMLstore.
Cause: This is probably expected behavior. The SQLite store ensures that all data is written correctly to disk—see“Configuringa
SQLite Store’s Save Behavior.”
Remedy: First determine whether the time taken to save will benoticeable to the user. This is typically likely to be the case only if youconfigure your application to frequently save automatically—for example, afterevery edit that the
user makes. First, consider changing the store’s save behavior (switch off full sync). Then consider saving data only after a setperiod (for example, every 15 seconds) instead of after every edit. Ifnecessary, consider choosing a different store—for example,
the binary store.
解决卡顿的方法:
1 关闭fullfsync,然后调整频率
2如果还不满意,自己去手工每15秒调用保存(卡顿)方法,算是负载均衡(不知是否用多线程)
3使用二进制的数据流,就不会出现此问题.
Problem: You are using an SQLite store and notice that it takeslonger to save to the SQLite store than it does to save the same data to an XMLstore.
Cause: This is probably expected behavior. The SQLite store ensures that all data is written correctly to disk—see“Configuringa
SQLite Store’s Save Behavior.”
Remedy: First determine whether the time taken to save will benoticeable to the user. This is typically likely to be the case only if youconfigure your application to frequently save automatically—for example, afterevery edit that the
user makes. First, consider changing the store’s save behavior (switch off full sync). Then consider saving data only after a setperiod (for example, every 15 seconds) instead of after every edit. Ifnecessary, consider choosing a different store—for example,
the binary store.
解决卡顿的方法:
1 关闭fullfsync,然后调整频率
NSPersistentStoreCoordinator *psc = <#Get a persistent store coordinator#>; |
NSMutableDictionary *pragmaOptions = [NSMutableDictionary dictionary]; |
[pragmaOptions setObject:@"NORMAL" forKey:@"synchronous"]; |
[pragmaOptions setObject:@"1" forKey:@"fullfsync"]; |
NSDictionary *storeOptions = |
[NSDictionary dictionaryWithObject:pragmaOptions forKey:NSSQLitePragmasOption]; |
NSPersistentStore *store; |
NSError *error = nil; |
store = [psc addPersistentStoreWithType:NSSQLiteStoreType |
configuration: nil |
URL:url |
options:storeOptions |
error:&error]; |
3使用二进制的数据流,就不会出现此问题.
相关文章推荐
- token 6.x-1.17 "preg_match_all() expects parameter 2 to be string, array given in token_scan()" 问题解决
- undefined reference to" 问题解决方法
- "undefined reference to" 问题解决方法
- "undefined reference to" 问题解决方法
- [Trouble Shoot]hibernate中的Failed to load class "org.slf4j.impl.StaticLoggerBinder"问题的解决方法
- 解决android studio ADB无响应的问题:If you'd like to retry,then please manually kill "adb.exe"
- Project property "XFire services.xml path" does not refer to a valid file问题解决
- "undefined reference to" 问题解决方法
- hadoop "File /user/<user>/input/conf/slaves could only be replicated to 0 nodes, instead of 1"问题及解决办
- Java解析DBF文件,错误Failed to parse Number: For input string: "-.---" 或读取不出数据或乱码问题都在这里解决
- ubuntu12.04.4下出现"(sublime:12386): Gtk-WARNING **: Failed to load type module: (null)"问题及解决方法
- "cannot locate symbol "sqlite3_enable_load_extension" referenced by "sqlite3" 问题解决
- "Failed to load session “ubuntu"问题解决总结
- 问题解决:Error -27776: Server "XXX" shut connection during attempt to negotiate SSL session
- "undefined reference to" 问题解决方法
- undefined reference to" 问题解决方法
- 解决xhost:unable to open display""的问题
- "undefined reference to" 问题解决方法
- Linux解决perl: warning: Falling back to a fallback locale ("en_US.utf8").问题
- "undefined reference to" 问题解决方法