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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:34:27+00:00 2026-05-26T19:34:27+00:00

I’m trying to use as little memory as possible in my code. I’ve tried

  • 0

I’m trying to use as little memory as possible in my code. I’ve tried two ways of sending a custom class object to a method. I’m not sure if there is any difference between these two approaches. Say I have 2 classes, Class1 and Class2 each with their own class variables and methods of course.

All code is written in Class1

Approach 1:

Class2 *class2Object = [[Class2 alloc] init];

[self doSomething: class2Object];

[class2Object release];

-(void) doSomething: (Class2 *) var {
int a = var.a;
}

Approach 2:

Class2 *class2Object = [[Class2 alloc] init];

[self doSomething: &class2Object];

[class2Object release];

-(void) doSomething: (Class2 **) var {
int a = var->a;
}

Is there any performance difference between these two methods? Is the second approach completely pointless? Why is it that I can use the dot notation in Approach 1, but have to use -> in Approach 2?

Thanks.

  • 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-05-26T19:34:27+00:00Added an answer on May 26, 2026 at 7:34 pm

    Is there any performance difference between these two methods?

    indeed, there is a negligible difference in performance, due to the fact that in approach 2 you have one more indirection (i.e., pointer dereferencing, see also below); so, approach 1 will save you a few clock cycles.

    Is the second approach completely pointless?

    approach 2 is useful,e.g., when you would like to allocate a new instance of type Class2 and pass it back to the caller through the same argument; say:

     - (bool)cloneObject:(Class2 **)var;
    

    you pass an object in; the object is cloned and returned in var; since it is the address of the object itself which changes, you need to have a pointer to the pointer to the object in order to set the new address; the return value only states if the operation was executed correctly.

    Of course, in this example, it would be more natural doing:

         - (Class2)cloneObject:(Class2*)var;
    

    i.e., you return the pointer to the object newly allocated, but the use case still holds.

    Why is it that I can use the dot notation in Approach 1, but have to use -> in Approach 2?

    in the second case you have to use -> because you are not dealing with a pointer to an object directly; you are dealing with a pointer to a pointer to an object; what you need do in such cases is, first of all, “dereferencing” your pointer (i.e., applying operator *) in order to get a pointer to the object, then accessing the latter as you would do otherwise; this could be written like:

     (*var).a
    

    here, var is a pointer to a pointer to an object of Class2; *var is the result of dereferencing it, so you have a pointer to an object of Class2; finally, .a is the syntax to access an object property. the syntax:

    var->a
    

    is simply a “shorthand” for the operations described above.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.