archiveRootObject takes VERY long

Discussion in 'Mac Programming' started by Till Roenneberg, Sep 11, 2008.

  1. macrumors newbie

    Joined:
    Aug 22, 2008
    #1
    In my Cocoa application (not document based), I write a key-coded array to the disc and the method works perfectly. The only drawback is that it takes ages (OS 10.4.1). Granted, the file is 6 MB but should it really take several minutes? Any suggestions why this is so slow and how to make it faster?

    Thanks,
    Till


    NSMutableDictionary *rootObject = [NSMutableDictionary dictionary];
    [rootObject setValue: [here, I pass an NSMUtableArray created in the program]
    forKey:mad:"channels"];
    [NSKeyedArchiver archiveRootObject: rootObject toFile: path];
     
  2. macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #2
    Build a debug version and run and attach Shark to it to see where its spending so much time.

    And, well, a 6 meg mutable array? Geeze. Write a custom data storage class or something. Ask Google, there's all kinds of stuff out there.
     
  3. thread starter macrumors newbie

    Joined:
    Aug 22, 2008
    #3
    speed is compiling dependent

    Thanks. I am new to Cocoa and I still have to learn a lot before writing a custom data storage class (BTW, I couldn't find anything obviously useful in Google under these key words).

    I just realised that if I compile for powerPC, the save process is very fast but when I compile for intel, it becomes unbearably slow.
    Any idea why?
     
  4. macrumors member

    Joined:
    Aug 16, 2008
    #4
    I know that iPhone has SQLite ability built in, which would be perfect for this type of application - but I'm too new at Obj-C to know whether it's part of Cocoa or not. (if not, i'm sure you can find a library for it somewhere)
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    What sort of data are you saving? At 6Mb in size I am assuming it's binary data, not text. Images? Audio? Have you looked at using a package filetype instead (basically a directory that acts as a file). This is how Pages etc saves it's data. The advantage of this is that you can save the data in it's native format which should be quicker.
     
  6. thread starter macrumors newbie

    Joined:
    Aug 22, 2008
    #6
    I am saving channels of experiments. They are custom classes that can hold a variety of data, times and values of time series, channel descriptions as text. Since I am displaying the channels and their content in a lot of windows, they have property lists so that they can easily be updated in tables. The files are dynamic, so that more channels can be added, more information can be added to existing channels (data types which are another custom class with properties). In future, there may be an extension to saving graphs with the channels but presently, it's only Arrays, Strings, and Properties.

    Thanks Till
     
  7. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    In that case it sounds like something in your code is causing the archiver to run very slowly for some reason. The above suggestion to profile in Shark is the best way forward: find out what the code is spending it's time doing and then try and fix that...
     

Share This Page