Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8344313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:19:42+00:00 2026-06-09T06:19:42+00:00

I am optimizing an objective-c application, and within that application there is a large

  • 0

I am optimizing an objective-c application, and within that application there is a large NSString containing about 4000 sentences; don’t ask why… but there is.
It is randomly selecting a sentence and returning it.

This is the code (I shortend the centenses):

NSString *sentences[] = {@"For crying out loud", @"Too much information", @"Tomorrow", @"Tonight", @"I don't know", @"Forever and ever ", @"Lets get high", @"Foreigner ", @"Sick"};

self.responses = malloc(sizeof(self.responses)/sizeof(void*));
memcpy(strings, self.responses, sizeof(sentences)/sizeof(void*));

[...]

[self performSelector:@selector(didRecieveMessage:) withObject:self.responses[rand() % sizeof(self.responses)] afterDelay:rand() % 15 + 2];

Now, this needs to be optimized. I was thinking of including the sentences within the SQLLite Db and call the DB to fetch the random sentence, but are there any better ways to do this? E.g. reading a random line from a text file, or Plist file? And if so, how do I do it?
Memory is of course one of the most important aspects.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:19:45+00:00Added an answer on June 9, 2026 at 6:19 am

    Well you could start by not copying the whole array and taking up twice as much memory with the memcpy.

    I see some cut and paste fog in here but its pretty apparent that what should have been done is use NSArray for the initial array and not do the memcpy of the entire array.

    Other than that put it in sqlite and do a query and you wont have all this stuff in memory. If this is iOS I would definitely dump this data into sqlite. Any kind of ref data that size should not be in memory.

    This is prime for Sqlite….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Another question of mine about optimizing Objective C programs inspired the following: does anyone
I have been optimizing my website but the one problem that stands in my
I'm optimizing a PNG encoder for use within Flash SWFs (but I'm writing it
Currently optimizing an application at work. There are many files in some of the
I'm currently optimizing an application, one of the operations that is done very often
I'm interested in optimizing the hashing of some large files (optimizing wall clock time).
I’m working on optimizing some of my queries and I have a query that
I am currently optimizing a PHP application and found one function being called around
I need some help optimizing queries on 2 tables. One will contain about a
Possible Duplicate: Optimizing Android application before release How can we lower battery consumption in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.