diff options
Diffstat (limited to 'android/database/CursorWindow.java')
-rw-r--r-- | android/database/CursorWindow.java | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/android/database/CursorWindow.java b/android/database/CursorWindow.java index a75372ff..f84ec65f 100644 --- a/android/database/CursorWindow.java +++ b/android/database/CursorWindow.java @@ -16,8 +16,7 @@ package android.database; -import dalvik.system.CloseGuard; - +import android.annotation.BytesLong; import android.content.res.Resources; import android.database.sqlite.SQLiteClosable; import android.database.sqlite.SQLiteException; @@ -26,8 +25,10 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.Process; import android.util.Log; -import android.util.SparseIntArray; import android.util.LongSparseArray; +import android.util.SparseIntArray; + +import dalvik.system.CloseGuard; /** * A buffer containing multiple cursor rows. @@ -94,19 +95,29 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { * @param name The name of the cursor window, or null if none. */ public CursorWindow(String name) { + this(name, getCursorWindowSize()); + } + + /** + * Creates a new empty cursor window and gives it a name. + * <p> + * The cursor initially has no rows or columns. Call {@link #setNumColumns(int)} to + * set the number of columns before adding any rows to the cursor. + * </p> + * + * @param name The name of the cursor window, or null if none. + * @param windowSizeBytes Size of cursor window in bytes. + * <p><strong>Note:</strong> Memory is dynamically allocated as data rows are added to the + * window. Depending on the amount of data stored, the actual amount of memory allocated can be + * lower than specified size, but cannot exceed it. + */ + public CursorWindow(String name, @BytesLong long windowSizeBytes) { mStartPos = 0; mName = name != null && name.length() != 0 ? name : "<unnamed>"; - if (sCursorWindowSize < 0) { - /** The cursor window size. resource xml file specifies the value in kB. - * convert it to bytes here by multiplying with 1024. - */ - sCursorWindowSize = Resources.getSystem().getInteger( - com.android.internal.R.integer.config_cursorWindowSize) * 1024; - } - mWindowPtr = nativeCreate(mName, sCursorWindowSize); + mWindowPtr = nativeCreate(mName, (int) windowSizeBytes); if (mWindowPtr == 0) { throw new CursorWindowAllocationException("Cursor window allocation of " + - (sCursorWindowSize / 1024) + " kb failed. " + printStats()); + windowSizeBytes + " bytes failed. " + printStats()); } mCloseGuard.open("close"); recordNewWindow(Binder.getCallingPid(), mWindowPtr); @@ -773,6 +784,16 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { return "# Open Cursors=" + total + s; } + private static int getCursorWindowSize() { + if (sCursorWindowSize < 0) { + // The cursor window size. resource xml file specifies the value in kB. + // convert it to bytes here by multiplying with 1024. + sCursorWindowSize = Resources.getSystem().getInteger( + com.android.internal.R.integer.config_cursorWindowSize) * 1024; + } + return sCursorWindowSize; + } + @Override public String toString() { return getName() + " {" + Long.toHexString(mWindowPtr) + "}"; |