Uploading Images, Working Memory, And Storage.

Discussion in 'Mac Programming' started by NeonKingKong, Feb 11, 2010.

  1. NeonKingKong macrumors member

    NeonKingKong

    Joined:
    Nov 14, 2008
    Location:
    Portland, OR
    #1
    Hello. I'm in the process of porting an application originally in java to cocoa, but I'm rewriting it to make it much better, since I prefer cocoa a lot anyway.

    One of the problems I had in the application, was that when you uploaded images to it, I had the images created, (as say an NSImage object) and then I just had them sitting in memory, the more I uploaded the more memory they took up, and I ended up running out of memory.

    My question is this: if I am going to have users upload images to this application in cocoa, how should I go about storing them? I don't just want to copy the file paths, because I want what is saved to contain the images, etc. Is there any way to upload an image and copy it into a different place only for my application? Then load that image with the new path name as needed?

    Only I would like it all to be consolidated. I'm going to implement saving by archiving one "master" object into an NSData*- so I'd like the images to be saved with that.

    Is there a temporary location maybe where I could write the images to disk for my application, and then when I saved, they would all be archived into a single file? Also, how do I do this? Thanks.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Can you be more specific on how you're using these images in your application?

    Yes, just copy it to either a temporary location or your app's Application Support folder.

    Why? Writing one huge file is not very efficient unless you have some smart format that only writes what has changed. If you're dealing with some type of document format that users can control themselves and you don't need cross-platform support, use a bundle and write each file individually inside it.

    Look at NSFileManager, NSTemporaryDirectory().
     
  3. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #3
    For what you want to do, I would consider making a wrapper. Then you can just put copies of the files right into it. Study the documentation for NSFileWrapper to see if this might work for you. The double-edged sword is that you would end up with a document file that is a disguised directory, similar to an .app bundle or .rtfd, which would not be very network-portable, if that is a concern, but OTOH, the user would have an easy time accessing its contents (the individual images).

    The other alternative would be to implement some sort of archive, where you could store the images as files in the archive, which could be extracted as needed instead of everything being loaded directly into memory (which is what you have now). The xar format has a distinct appeal to it, but finding an app that would decompress it (if you want the user to be able to recover the images in it) might present a challenge. There is OS support for xar archives (documentation consists of xar.h in the sdk), which are what .pkg files are made of, but you would probably find that to be more trouble than it is worth, at least for now.
     
  4. NeonKingKong thread starter macrumors member

    NeonKingKong

    Joined:
    Nov 14, 2008
    Location:
    Portland, OR
    #4
    Thanks very much for your replies. The user would not need to access the images directly except from inside the application, and eventually I would like to port this to a web app by using bombastic and cappuccino. (if it's possible) So, I would like storage to be as simple as possible. I will try out the different solutions you both offered. Thanks!
     

Share This Page