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 8457339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:47:11+00:00 2026-06-10T12:47:11+00:00

If I do: foos[i] = [[Foo alloc] init]; foos[i].prop = @bar; [foos[i] baz]; …

  • 0

If I do:

foos[i] = [[Foo alloc] init];
foos[i].prop = @"bar";
[foos[i] baz];

… Is that less efficient than:

Foo *foo = [[Foo alloc] init];
foo.prop = @"bar";
[foo baz];
foos[i] = foo;

or are they equivalent?

  • 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-10T12:47:12+00:00Added an answer on June 10, 2026 at 12:47 pm

    If your array is a simple a C array (Foo * array[11];), then it will not have significant performance impact.

    If your array is an NSMutableArray (or another subscriptable NS-type), then it will have to call the method’s implementation repeatedly (which uses short circuited dispatch), so that will introduce some overhead. Although some would consider it a micro-optimization. In this case, the compiler cannot know what the implementation returns, so it cannot omit the calls.


    Here are basic wall clock time results:

    MRC:

    NSArray: 27 seconds

    C Array: 18 seconds

    ARC:

    NSArray: 31 seconds

    C Array: 18 seconds

    and the program (which you can perform the obvious ARC changes to to test ARC):

    const int NIter = 10000;
    
    __attribute__((noinline)) void fn1() {
      @autoreleasepool {
        NSMutableArray * foos = [NSMutableArray array];
        for (size_t idx = 0; idx < NIter; ++idx) {
          NSMutableString * str = [NSMutableString new];
          foos[0] = str;
          [foos[0] length];
          [foos removeAllObjects];
          [str release];
        }
      }
    }
    
    __attribute__((noinline)) void fn2() {
      @autoreleasepool {
        NSMutableString * foos[1];
        for (size_t idx = 0; idx < NIter; ++idx) {
          foos[0] = [NSMutableString new];
          [foos[0] length];
          [foos[0] release];
          foos[0] = 0;
        }
      }
    }
    
    int main() {
      for (size_t idx = 0; idx < NIter; ++idx) {
        if (UseNSArray) {
          fn1();
        }
        else {
          fn2();
        }
      }
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following models: class Foo has_and_belongs_to_many :bars end class Bar has_and_belongs_to_many :foos
I have in my app/views/bar/index.html.haml the following %p= render partial: 'foo', collection: @foos the
I have a class Foo that uses another class Bar to do some stuff.
I'm trying to sort column Foo that has one Bar . Currently, I'm using
I have a table Foo that has a polymorphic belongs_to association called bar .
I have 2 django models: class Foo(models.Model): baz = models.CharField() class Bar(models.Model); foo =
given this coffeescript data = Foo: B Foos: [ A, B ] Blah: Id:
I've got a MySQL table with Foos. Each Foo has a numeric non-unique code
given this xml: <root> <list> <!-- foo's comment --> <item name=foo /> <item name=bar
I'm trying this: {:id => 5, :foos => [1,2,3]}.each {|k,v| v.to_s} But that's returning

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.