Hello list
I wrote a function that attempts to calculate the cached page size for a given page size, to be passed as the sz parameter for sqlite3_config(SQLITE_CONFIG_PAGECACHE, buf, sz, N). It appears to work so far (with 3.6.3) but I'd appreciate if anyone could go over it and see if they can find any holes, or if it is likely to be broken by future SQLite releases. static size_t _get_cached_page_size(size_t page_size) { sqlite3 *db = 0; int rc, size, size_hi; unsigned char *mem; /* ALLOCATE MEMORY FOR 3 DOUBLE-SIZE PAGES */ mem = malloc(page_size * 6); /* CONFIGURE SQLITE PAGE CACHE FOR 3 DOUBLE-SIZE PAGES */ rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, mem, page_size * 2, 3); /* INITIALISE SQLITE LIBRARY */ rc = sqlite3_initialize(); /* OPEN TEMP DATABASE */ rc = sqlite3_open(":memory:", &db); /* SET PAGE SIZE (calls sqlite3_exec() with "PRAGMA page_size=<page_size>") */ rc = _pragma_set_int(db, "page_size", (int)page_size); /* CREATE TEMP TABLE */ rc = sqlite3_exec(db, "CREATE TABLE _temp (data int)", 0, 0, 0); /* GET LARGEST MEMORY SIZE REQUESTED TO PAGE CACHE */ rc = sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &size, &size_hi, 0); /* SHUT DOWN SQLITE LIBRARY */ rc = sqlite3_shutdown(); /* FREE MEMORY AND RETURN SIZE ROUNDED UP TO NEAREST 8 BYTES */ free(mem); size_hi = (size_hi + 7) & ~7; return size_hi; } Cheers, Dave. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users