3

Main Question

How the cursor retrieves data from SQlite? does it refers to database file addresses dynamically? or loads it fully to the memory? though i know the dalvik virtual machine is address based and the the first assumption is more likely to be true, as the nature of RAM memory and phone storage are almost the same.

So my main question is to know how the data are load? from loading to memory? or just addressing to database file content?

To clarify: (the sample is just for clarifying. you can skip it)

The question is raised from the point that:

I have created an app which loads data from sqlite and displays them in listview. the databsase grows up using user data by time. Now, when the database goes larger, is it required to load data to listview in a manner like using load more or pagination? or its true to load them in one place? although, pagination would be better for responsiveness but, when trying to export data to xls or pdf format, is it possible to retrieve a cursor to all the database and save data in xls or pdf?

the messaging app of android loads all messages in one place and has causes no problem even when i have 3000 messages in one thread.

Ali sh
  • 464
  • 5
  • 14
  • Similar question: http://stackoverflow.com/q/3679664/844882 – Alex Lockwood Jun 08 '14 at 07:56
  • thanks. but that not seems to be much similar to my question. there they are talking about database optimization. but so what about apps which using "pagination" and "load more"? do they just waste their time? because they could optimize their database? i am not talking about apps which load data from the net, but about apps like "viber" which loads conversation from database but uses "load more" also. anyway.. i updated my question to remove disambiguation. – Ali sh Jun 08 '14 at 09:27
  • The messaging app does not show 3000 messages at the same time on the screen. – CL. Jun 08 '14 at 09:49
  • Thanks for comment. Yes i know about adapterView and the way it shows the listview views. but the where the data in cursor themselves coming from? cursor holds data in itself? or loads them dynamically by accessing to the database file? memory or file.. that's the question :) – – Ali sh Jun 08 '14 at 18:58

1 Answers1

2

Seems that data for Cursor is stored in memory or some kind of cache file (it's implementation details as I've properly mentioned). There are two possible ways to proof / show why it's not original DB file. I'm sure there should be also some kind of more theoretical explanation.

  • Take a look at SQLiteCursor source (it's available in your sdk platform installation): it's based on CursorWindow which is

A buffer containing multiple cursor rows.

A CursorWindow is read-write when initially created and used locally. When sent to a remote process (by writing it to a Parcel), the remote process receives a read-only view of the cursor window. Typically the cursor window will be allocated by the producer, filled with data, and then sent to the consumer for reading.

Also, from the source it looks like that Window contains all data in that buffer.

  • Create test application with test DB with lot of records. Request all records and show in the list. While list is showing keep constantly changing db content and observe that list content is not changed (I assume eliminate usage of requery() and related deprecated stuff).
sandrstar
  • 12,503
  • 8
  • 58
  • 65