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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:09:21+00:00 2026-05-29T11:09:21+00:00

This code all works, but I’m basically blundering around my lack of knowledge in

  • 0

This code all works, but I’m basically blundering around my lack of knowledge in C. The code works and does seem to be faster than creating NData instances every time I need to make a method call. But is it okay (no leaks, no pointer gotchas)?

I’m particularly worried about the cast to Byte* which was necessary to get the compiler to pipe down:

Here’s is the code, simplified:

- (BOOL) isThisMethodOkay {
    // I have a length, range and an NSData instance
    Byte bytes[self.data.length]; 
    [self.data getBytes:&bytes range:range];
    return [self doSomething:bytes length:length]
}

- (BOOL) whatAboutThis {
    return [self doSomething:(Byte*)self.data.bytes length:self.data.length];
}

- (BOOL) doSomething:(Byte*)bytes length:(NSUInteger)length {
    return (length == CHECK_LENGTH && data1(bytes) == CHECK_DATA_1);
}

static int data1(Byte* bytes) {
    int retVal = (int)bytes[1];
    return retVal;
}

Note: all code is under ARC.

  • 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-29T11:09:22+00:00Added an answer on May 29, 2026 at 11:09 am

    There are no memory leaks since bytes is a VLA which uses the stack. If you plan on handling any large amounts of data you may want to consider allocating that data on the heap and then freeing it when done. (You also should be able to use uint8_t instead of Byte)

    - (BOOL) isThisMethodOkay {
        // I have a length, range and an NSData instance
        uint8_t *bytes = malloc(self.data.length); 
        [self.data getBytes:&bytes range:range];
    
        BOOL result = [self doSomething:bytes length:length];
        free(bytes);
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried this code. All works, but I can't find a way to reach
For some reason, this code works all chrome, safari, and ei but not on
ok, this code works just fine in Chrome. But, for some reason it does
after searching google i got a code which works but this code download all
This code below works in all web browsers except IE: <input type="text" name="passwordLogin" value="Password"
web page : http://sideradesign.com/eco-art/gallery/ This code works fine in all brwosers except IE8 (haven't
I have this code which gets WP posts, but it gets all the posts
I'm having this problem while writing my own HashTable. It all works, but when
i'm using Valums Ajax uploader. all works great in Mozilla with this code: View:
I have this code, and all works well in my local server. The email

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.