开发者

NSMutableArray with 500 objects.

I have an array that has 500 objects, each object is nessisary because each one represents another question for my program. My program seems to be taking quite a bit of memory roughly around 50 mb on a iPhone 4. I see that when the array is in use it seems to lag the program a bit. Would an array of this size cause lag when used? Can someone give me an estimate of how much memory this array is using?

I was thinking maybe saving开发者_如何学编程 the array to a plist file and using the array from there, would that save memory?

Thanks, Jacob


Assume a question contains the following

    typedef struct
    {
       char _question[255];
       char _answerA[255];
       char _answerB[255];
       char _answerC[255];
       char _answerD[255];

       int _correctAnswer;

} question;

Save out to a file 500 of these structs in order of the questions.

All 500 questions would take up roughly 0.609874725 mbs with this example.

Then open a file and seek to the question

    Handle fOpen... 
        fSeek...  questionNumber *sizeof(question) ;
        read in one question fRead...
    fClose(Handle)


First off, we can't tell you how much memory your array takes because it depends on the objects being stored. However, you can use the Instruments tool (Build -> Profile) to look at that stuff.

Secondly, for 500 objects, I would seriously consider using either SQLite or CoreData for your store.It is highly unlikely that you need all 500 questions in memory at the same time - one or two should probably do it, after all, how many questions can be answered at one time?


First of all it's absolutely impossible to give an estimate unless you tell the size of the object stores. But never the less it's not a good idea to load everything into memory. You can store questions in small chunks (say 10 questions each) in simple plist files. As for me I prefere to store such info in a database (CoreData manages memory very well).


I cannote help with the memory stuff, but it occurs to me that perhaps a different loading strategy may be the answer. For example, I would presume that the user is not going to read or answer all 500 questions in one go. So is it possible to load then in blocks as the user needs them? or if you have dependencies between questions, can you only load the ones that are current relevant? Also storing them in a Core Data database so you can query for the ones needed for the display might help as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜