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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:25:56+00:00 2026-05-16T03:25:56+00:00

I can add bytes to a NSMutableData instance easily by using the appendData method,

  • 0

I can add bytes to a NSMutableData instance easily by using the appendData method, however I do not see any similar method for removing data? Am I overlooking something, or do I need to create a new object and copy over only the bytes I need?

  • 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-16T03:25:56+00:00Added an answer on May 16, 2026 at 3:25 am

    Please see the documentation of the following method:

    - (void)replaceBytesInRange:(NSRange)range 
        withBytes:(const void *)replacementBytes 
        length:(NSUInteger)replacementLength
    

    Apple says the following:

    If the length of range is not equal to
    replacementLength, the receiver is
    resized to accommodate the new bytes.
    Any bytes past range in the receiver
    are shifted to accommodate the new
    bytes. You can therefore pass NULL for
    replacementBytes and 0 for
    replacementLength to delete bytes in
    the receiver in the range range. You
    can also replace a range (which might
    be zero-length) with more bytes than
    the length of the range, which has the
    effect of insertion (or “replace some
    and insert more”).

    To remove 10 byte from the end, use:

    data.length = data.length - 10;
    

    It could also be done via replaceBytesInRange, but it’s in fact much faster, because the bytes are not really removed. Instead only the internal size variable is changed and NSMutableData will behave as if the bytes were removed. IOW, this is a O(1) operation (that means it will always take equally long to perform, regardless of how many bytes you remove), and it is very fast.

    To remove 10 byte from front, use:

    [data replaceBytesInRange:NSMakeRange(0, 10) withBytes:NULL length:0];
    

    To remove 10 bytes in the middle (e.g. after 20 bytes), use:

    [data replaceBytesInRange:NSMakeRange(20, 10) withBytes:NULL length:0];
    

    replaceBytesInRange is a O(n) operation, though. The time required to perform the operation depends on how many bytes the data object has and where you remove them, as all bytes right to the remove location must be shifted to the left. It is still pretty fast and only limited by the throughput of your computer’s memory (RAM). If you have 10 MB of data and you remove 1 MB from front, 9 MB are copied to fill the gap of the just removed MB. So the speed of the operation depends on how fast your system can move 9 MB of RAM from one address to another one (which on my system takes 0.2 milliseconds for 9 MB).

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

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 515k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Database will be the preference, for persistence, but you can… May 16, 2026 at 6:38 pm
  • Editorial Team
    Editorial Team added an answer You can do it in sed as: sed -r -i… May 16, 2026 at 6:38 pm
  • Editorial Team
    Editorial Team added an answer Try to use sp_msforeachdb stored procedure like so: create table… May 16, 2026 at 6:38 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm using system.net.mail and have a textbox that users can enter their email address
Consider the following code: byte[] bytes = new byte[] { 1, 2, 5, 0,
I am out of ideas here, so I'm hoping someone can help. Here is
I have an embedded web server written in C using uIP libraries, in a
I am trying to create a zip file using servlets but it returns me
I'd like to add compile time asserts into the following C++ code (compiled with
I've got an enumeration in my game. A simple string message with an appended
Well, I completely get the most basic datatypes of C, like short, int, long,
I create a JTree and model for it out in a class separate to
I have a PKCS#5 encrypted PKCS#8 RSA private key stored in a disk file

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.