Android Question blob or .jpg

Discussion in 'Android Questions' started by Enthousiastic, Mar 31, 2015.

  1. Enthousiastic

    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
     
  2. sorex

    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.
     
  3. Troberg

    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.
     
  4. DonManfred

    DonManfred Expert Licensed User

    Additional to this. The required space is the same. A 100kb jpg will need 100kb space on SdCard and also 100kb in the Database.
     
    Peter Simpson likes this.
  5. sorex

    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 :)
     
  6. DonManfred

    DonManfred Expert Licensed User

    Correction 512,1024,2048,4096,8196,[..]
     
  7. DonManfred

    DonManfred Expert Licensed User

    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.
     
  8. sorex

    sorex Expert Licensed User

    my values were right as I substracted that byte already ;)
    (page-byte=overhead)
     
  9. Troberg

    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.
     
  10. keirS

    keirS Well-Known Member Licensed User

    This is not true of SQLite. The only difference between a BLOB and a TEXT field is a TEXT field is UTF encoded.
     
  11. sorex

    sorex Expert Licensed User

    is it converted to 7 bit or stored as 0X8E5C34343AD74B5E9F9DD8E like string?
     
  12. tchart

    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.
     
    DonManfred likes this.
  13. Troberg

    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.
     
  14. keirS

    keirS Well-Known Member Licensed User

    There is no variable encoding for a Blob. It stores literal bytes.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice