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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:10:05+00:00 2026-06-12T01:10:05+00:00

When setting up NSMutableData like this: NSMutableData* mRgb = [NSMutableData dataWithCapacity:3]; ((char*)[mRgb mutableBytes])[0] =

  • 0

When setting up NSMutableData like this:

NSMutableData* mRgb = [NSMutableData dataWithCapacity:3];
((char*)[mRgb mutableBytes])[0] = 10;
((char*)[mRgb mutableBytes])[1] = 90;
((char*)[mRgb mutableBytes])[2] = 160;

I have the problem that the length is still 0:

int len = [mRgb length]; // Is 0!

Why is that so?

  • 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-06-12T01:10:06+00:00Added an answer on June 12, 2026 at 1:10 am

    dataWithCapacity just reserves that many bytes in memory, it does not mean the data is that size yet.

    An example of this would be when receiving an image from the internet. Up front you do not know how large the image will be, so just create a Data object with capacity for 1MB, that way you do not continually need to resize the data as you receive more of it.

    What you want to use is the dataWithLength method, which creates a data objects containing that many bytes from the start. Or you can call setLength:N to change how much of the data is in use.

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

Sidebar

Related Questions

After setting up a replication on my server (SQL2005) I have noticed that default
Setting up CI within Microsoft Team Foundation Server, I have a build that will
setting is the following: I have a homepage where I display a diagram that
Setting up a project structure; I am thinking is it better to have somewhat
Setting up a new database that has a comments table. I've been told to
Setting up a WCF service that uses the webHttpBinding... I can return complex types
sorry if this question has already come up but I couldn't find anything that
Setting variables as returned lists from functions that contain variables as a returned list
I am sending a file to the server. Like in this tutorial: http://zcentric.com/2008/08/29/post-a-uiimage-to-the-web/#comment-8145 -
Setting: Multiplayer team game. Problem: Each player has a 1 to 5 star rating

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.