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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:49:40+00:00 2026-05-23T11:49:40+00:00

I’ve got a really simple C struct like so: typedef struct { int tag;

  • 0

I’ve got a really simple C struct like so:

typedef struct {
    int tag;
    CGPoint position;
} Place;

That is, all scalar types and no pointers in the struct.

Then I’ve got an array of those points like so:

 Place *dynamicPlaces = calloc(numberOfPlaces, sizeof(Place));

So each element of dynamicPlaces ought to be (unless I’ve mixed something up… it’s certainly possible with me and pointers…) a struct of type Place, initialized with all its members to 0, yeah? So far so good.

Then I’m trying to put that array in an NSData object to be sent over the network (along with the count of elements, not shown):

NSData *placesData = [NSData dataWithBytes:dynamicPlaces length:(sizeof(Place) * numberOfPlaces)];

I’m passing it the array directly, because if memory serves, the pointer dynamicPlaces is really pointing to the first struct element of the array, and then I tell it how many elements there are via length. I think this is good.

Finally, on the other side I do this when decoding my object.

[receivedData getBytes:receivedDynamicPlacesArrayPointer length:[receivedData length]];

But I get an EXC_BAD_ACCESS on that line and I can’t quite figure out why. As far as I can tell by the documentation, this ought to be storing the bytes from the NSData into a copied location in memory, and point to that blob with receivedDynamicPlacesArrayPointer.

It’s entirely possible I’ve made a mistake doing this, pointers trip me up, even though I think I understand them. Any help would be greatly appreciated.

  • 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-23T11:49:41+00:00Added an answer on May 23, 2026 at 11:49 am

    getBytes:length: docs say: “Copies a number of bytes from the start of the receiver’s data into a given buffer.”

    So you will need to first allocate memory for receivedDynamicPlacesArrayPointer yourself. Did you do that?

    In other words, you’d do like:

     Place* receivedDynamicPlacesArrayPointer = (Place*)malloc([receivedData length]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm making a simple page using Google Maps API 3. My first. One marker

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.