Re: [sqlite] surprising behaviour: in-memory db allocs less than file db

2013-06-22 Thread Drake Wilson
Quoth Stephan Beal , on 2013-06-23 03:07:02 +0200:
> file db:
> ==16021==   total heap usage: 856 allocs, 856 frees, 222,957 bytes allocated
> 
> vs :memory:
> ==16043==   total heap usage: 832 allocs, 832 frees, 203,430 bytes allocated
> 
> (Most of those allocs were done by my code, not sqlite.) i'm just curious
> how the second one could possibly allocate less than the first.

Here's a plausible explanation that I haven't thoroughly verified.
For both cases, for such a small database, all the actual data is
likely to wind up in the page cache.  For an in-memory database,
however, there's no need to manage an actual file descriptor,
filename, filesystem-based locks, possibly certain header
information...

Especially, note that on Unix-y platforms, where POSIX fcntl locking
is used, SQLite keeps internal global state matching up fds to inodes.
This is so that if you open the same database multiple times, and a
lock is ever taken on one connection, no other such connection can
close its fd before the first lock is released.  Otherwise, due to
fcntl's broken design, the close would release the lock immediately,
potentially resulting in database corruption.

The difference is not particularly large, and is easily explainable by
some combination of the above or similar.  If you want something more
exact, of course, feel free to run a source-level trace using your
favorite allocation analysis software and report back.  :-)

   ---> Drake Wilson
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] surprising behaviour: in-memory db allocs less than file db

2013-06-22 Thread Stephan Beal
Hi, all,

i just came across a curious behaviour and i'm interested to know what the
reason for it is (it's not a bug):

i have a very small test app with a tiny db (1 table, 2 records) where
valgrind reports me using more memory (and more allocs) for a file-based db
than the same :memory: db. That was very counter to my intuition.

file db:
==16021==   total heap usage: 856 allocs, 856 frees, 222,957 bytes allocated

vs :memory:
==16043==   total heap usage: 832 allocs, 832 frees, 203,430 bytes allocated

(Most of those allocs were done by my code, not sqlite.) i'm just curious
how the second one could possibly allocate less than the first.

:-?

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users