Android Question blob or .jpg

Enthousiastic

Active Member
Licensed User
Hello , I have a database for mine magazines with 205 records.The database has a field named cover which is the cover photo of the magazine stored as .jpg in sd card of mine android mobile phone.
The question is , which is more wise to have the cover field as .jpg or as blob ?
I put this question concerning the occupied memory . The 205 .jpg files or 205 blob files need more memory ?

Many thanks
Enthusiastic
 

sorex

Expert
Licensed User
I would just store a reference to the jpg file that is on the "disk".

it's easier, less code, less performace/resources needed too.
 

Troberg

Well-Known Member
Licensed User
I'd do as sorex suggests.

If you really want to store it in the database, a jpg or blob should be the same. The blob is simply a nonspecified binary object, in your case the jpg file.
 

sorex

Expert
Licensed User
actually the database one will always take more room, databases work with pages where they work in so worst case if the last byte of the file/blob falls in a new page you have almost a full page overhead. (not to mention pointer and records definitions.)

but this can be 511, 1023 2047, 4095, ... bytes depending on how the database is set up

it's all minimal tho :)
 

DonManfred

Expert
Licensed User
actually the database one will always take more room
sure, you are right... But it is not much i believe. And i think it is NOT a complete BLOCK on the SdCard. It will be smaller... Sure, the block is used now... But this one block probably can hold 100 references. Not just one.
 

sorex

Expert
Licensed User
my values were right as I substracted that byte already ;)
(page-byte=overhead)
 

Troberg

Well-Known Member
Licensed User
Blobs are usually not in paged space, instead, they are stored in some some separate blob space, and only a pointer to the blob space is stored in paged space.

Also, file systems are also paged (though it's called blocks), so you get the same problem there. I once got a nasty surprise when I unzipped an icon library, which zipped was only about 10 MB, and it promptly ate well over 1GB unzipped (this was in a time when a 1 GB disk was considered gigantic), because each 700-something bytes icon ate a 64kB block on the disk... Some file systems, such as ReiserFS has mechanisms to stuff several files (or the tails of files that only partially fills a page) into blocks that contains several such tails, but they are very few and none of the larger file systems do it. There is also a small performance overhead to tail packaging.
 

keirS

Well-Known Member
Licensed User
Blobs are usually not in paged space, instead, they are stored in some some separate blob space, and only a pointer to the blob space is stored in paged space.
This is not true of SQLite. The only difference between a BLOB and a TEXT field is a TEXT field is UTF encoded.
 

sorex

Expert
Licensed User
is it converted to 7 bit or stored as 0X8E5C34343AD74B5E9F9DD8E like string?
 

tchart

Active Member
Licensed User
A colleague of mine wrote a bird watching application that stored photos in sqlite. He said the database performed slower after adding many blob records. He's reverted to file system access. YMMV.
 

Troberg

Well-Known Member
Licensed User
If nothing else, if something gets corrupted, storing photos as files makes it much simple to at least recover something. Also, if the user would like to watch them or share them using some other app, it's also much easier.
 
Top