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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:00:38+00:00 2026-05-30T19:00:38+00:00

I normally work in Objective-C, but am now trying to integrate some C code

  • 0

I normally work in Objective-C, but am now trying to integrate some C code which I don’t know as well.

Let’s start with my Buffer object:

@interface Buffer : NSObject {

    int*  buffer_;
    int   numFrames_;
    int   idNumber_;
}

@property (nonatomic) int* buffer;
@property (nonatomic) int numFrames;
@property (nonatomic) int idNumber;

In another class I’m trying to dynamically create c arrays and stick them into the buffer of my buffer objects. It should be noted that I don’t know how many buffer objects I will need in advance.

for (i=0; i<[arrayOfFlags count]; i++) {

    NSNumber *flagObject = (NSNumber*)[arrayOfFlags objectAtIndex:i];
    int flagInt = [flagObject integerValue];


    Buffer *snippetBuffer = [[Buffer alloc] init];
    int returnArray[44000];
    snippetBuffer.buffer = returnArray;
    snippetBuffer.numFrames = 44000;
    snippetBuffer.idNumber = i;

    int k;

    // NSLog(@"creating snippet buffer at flag %d", flagInt);
    for (k = 0; k < 44000; k++) {

        snippetBuffer.buffer[k] = // insert some values here. 
    }
}

When I run this code all the buffer objects have the same data as the last one to be produced. I think what is happening is that the returnArray being overwritten at each iteration.

So how do I ensure that new memory is being allocated each time I instantiate a c array in a loop? (If that is indeed my problem).

Hope this question wasn’t too complicated. Please feel free to ask questions.

  • 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-30T19:00:39+00:00Added an answer on May 30, 2026 at 7:00 pm
    int returnArray[44000];
    snippetBuffer.buffer = returnArray;
    

    This is a wrong initialization for your snippetBuffer.buffer pointer, since returnArray is a local variable and gets destroyed at the end of the scope.

    Use instead

    snippetBuffer.buffer = (int*)malloc(44000*sizeof(int));
    

    Remember to call free to release the memory after you have done.

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

Sidebar

Related Questions

I'm somewhat new at C++ (I normally work in C#, but right now I'm
I don't normally work with IE7 simply because I hate it, but my latest
I normally don't work on Windows development, and am completely unfamiliar with the toolchain
I normally work with jQuery, which takes away most of the cross browser pain
I'm implementing AMF service methods for an flash front-end. Normally things work fine, but
I normally work these things out reasonably quickly, but this one is a headache.
I normally work on single threaded applications and have generally never really bothered with
I normally run VS 2008 at home and LINQ is built in. At work
I'll preface this by saying that I usually work in C#/.Net. Normally, I use
Normally I use imagecreatefromjpeg() and then getimagesize() , but with Firefox 3 I need

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.