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

  • Home
  • SEARCH
  • 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 6061947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:59:42+00:00 2026-05-23T08:59:42+00:00

I’ve been programming for a while in objective-c, but I’ve unfortunately never delved very

  • 0

I’ve been programming for a while in objective-c, but I’ve unfortunately never delved very deeply into C and memory pointers, although I do have a rudimentary understanding of them. I’m working with an array of CLLocationCoordinate2D structures, and I’m trying to figure out how to append to the array. First of all, I get the

NSString *aString; //a bunch of coordinates
CLLocationCoordinate2d *coordinates;
int length;

doSomethingCool(aString, &coordinates, &length);

after I do something cool, I want to preserve it in a class variable. If I simply do something like

points = newPoints

points contains the appropriate contents. However, if I try to do something like this:

points = malloc(sizeof(CLLocationCoordinate2D) * length);
points[0] = *newPoints;

points ends up with contents different from newPoints.

Ultimately my goal is to be able to append to points based on length, but I’m not going to be able to do that if I can’t get the above code to work. What am I doing wrong?

  • 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-23T08:59:42+00:00Added an answer on May 23, 2026 at 8:59 am

    Your code simply copies the first value of newPoints into the first value of points (*newPoints is equivalent to newPoints[0]).

    One situation is to make a new array, copy all values, switch the arrays, and free() the old one. For example:

    int* newvals = malloc(sizeof(int) * newcount);
    memcpy(newvals, vals, sizeof(int) * oldcount);
    free(vals);
    vals = newvals;
    

    You can also use realloc – its behavior is similar to the above (though it can fail!), but at times may be more efficient.

    Note that you simply can’t change the underlying pointer’s size in a safe and portable fashion. You will need to update your instance (“class”) variable with the new pointer.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I have a jquery bug and I've been looking for hours now, I can't
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.