Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: C++, storing temporary files.

  1. #1
    Join Date
    Sep 2009
    Location
    Canada, Montreal QC
    Beans
    1,809
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    C++, storing temporary files.

    Hello,

    I am working on a program that is intended to be a sort of social client for Youtube.
    The program must deal with video searches, downloads, previews and many more.

    I want to offer the user a thumbnail of the selected video.
    I have achieved the downloading of the image file, but now, a problem arises.

    I need a place to store these images and to delete them after.

    So far I have 2 approaches to this.

    One of them is to store them in the temporary directory, but I have not found a cross platform way to do this yet.

    Another one is to manage the file deletion myself, but I feel this is a too big burden on me and in the case of a crash, would leave garbage on the system.

    I am here to ask the advice about other possible approaches or a way to get the temporary folder in a portable way.

    The boost library seems to offer something, but I did not find the required function.

    Thank you.
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.
    Freedom is measured in Stallmans.
    Projects: gEcrit

  2. #2
    Join Date
    Feb 2009
    Beans
    789
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: C++, storing temporary files.

    Applications often create a directory called .bla where bla is the application name. These directories are used to store application configuration files, user preferences and other data. You could store your image files in there as well and delete them when the program finishes.

    Quote Originally Posted by cgroza View Post
    Another one is to manage the file deletion myself, but I feel this is a too big burden on me and in the case of a crash, would leave garbage on the system.
    Not necessarily, you could delete them the next time the application launches (i.e., check for image files, delete them if needed).
    "The eagle never lost so much time as when he submitted to learn from the crow."

  3. #3
    Join Date
    Sep 2009
    Location
    Canada, Montreal QC
    Beans
    1,809
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: C++, storing temporary files.

    Quote Originally Posted by simeon87 View Post
    Applications often create a directory called .bla where bla is the application name. These directories are used to store application configuration files, user preferences and other data. You could store your image files in there as well and delete them when the program finishes.



    Not necessarily, you could delete them the next time the application launches (i.e., check for image files, delete them if needed).
    This seems the best approach. Thank you.
    I am still open to other suggestions.
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.
    Freedom is measured in Stallmans.
    Projects: gEcrit

  4. #4
    Join Date
    Apr 2008
    Location
    Far, far away
    Beans
    2,148
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: C++, storing temporary files.

    Is there a reason not to use the tmpfile() function defined in stdio. It creates and opens tmp file and it will delete it when closed. Or tmpnam() if you need more control.

    I haven't needed to use this but I'd expect it works on all platforms - haven't checked that.

  5. #5
    Join Date
    Sep 2009
    Location
    Canada, Montreal QC
    Beans
    1,809
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: C++, storing temporary files.

    Quote Originally Posted by BkkBonanza View Post
    Is there a reason not to use the tmpfile() function defined in stdio. It creates and opens tmp file and it will delete it when closed. Or tmpnam() if you need more control.

    I haven't needed to use this but I'd expect it works on all platforms - haven't checked that.
    That seems to force me to download the same file multiple times if the same entry is selected 2 times. Because the temp file is deleted when it is destroyed, it would require me to keep many of them open while I need them, which is during all the time the application runs.
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.
    Freedom is measured in Stallmans.
    Projects: gEcrit

  6. #6
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

    Re: C++, storing temporary files.

    Are the cache files potentially reusable from session to session?

    What about using the same approach as a browser cache? Let it grow up to a defined size, then delete the oldest when you want to create new ones above the size limit? Or you could take the same approach as the trash and delete based on age with no strict size limit?

    Maybe you'd then need a "clear cache" option?

  7. #7
    Join Date
    Sep 2009
    Location
    Canada, Montreal QC
    Beans
    1,809
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: C++, storing temporary files.

    Quote Originally Posted by r-senior View Post
    Are the cache files potentially reusable from session to session?

    What about using the same approach as a browser cache? Let it grow up to a defined size, then delete the oldest when you want to create new ones above the size limit? Or you could take the same approach as the trash and delete based on age with no strict size limit?

    Maybe you'd then need a "clear cache" option?
    Yes, but what are the chances the user will have the same range of videos from session to session and that he will select the one I have a cached file for?
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.
    Freedom is measured in Stallmans.
    Projects: gEcrit

  8. #8
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

    Re: C++, storing temporary files.

    Quote Originally Posted by cgroza View Post
    Yes, but what are the chances the user will have the same range of videos from session to session and that he will select the one I have a cached file for?
    It's your application and you'd know better than I would, but, other than simply watching something again, could someone download a video, watch part of it and come back to it later perhaps?

  9. #9
    Join Date
    Sep 2009
    Location
    Canada, Montreal QC
    Beans
    1,809
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: C++, storing temporary files.

    Quote Originally Posted by r-senior View Post
    It's your application and you'd know better than I would, but, other than simply watching something again, could someone download a video, watch part of it and come back to it later perhaps?
    Maybe, but then the user will not need a preview. The user already saw it or watched some of it.
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.
    Freedom is measured in Stallmans.
    Projects: gEcrit

  10. #10
    Join Date
    Apr 2008
    Location
    Far, far away
    Beans
    2,148
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: C++, storing temporary files.

    Quote Originally Posted by cgroza View Post
    That seems to force me to download the same file multiple times if the same entry is selected 2 times. Because the temp file is deleted when it is destroyed, it would require me to keep many of them open while I need them, which is during all the time the application runs.
    As mentioned, the tmpnam() function gives you more control as it doesn't force a delete when closed. You just use it to generate a unique name and then pass that as filename to open.

    Another way would be to generate the filename as a hash of the original video url - that way the same url would always map to the same filename. There are some very simple/fast hash functions that would work for that and it would fit into a cache scheme better too. eg. if you generate the filename and it already exists then you know it's been downloaded already, or if length is not correct then you know a resume d/l is needed.

    (This is probably a better ref for MurmurHash3)
    Last edited by BkkBonanza; June 11th, 2011 at 09:54 PM.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •