user2515165
user2515165

Reputation: 35

NSMutableData increment the underneath pointer and pass it to other APIs

I have been given a task to replace all uint_8 * to NSMutableData. In the existing code, a lot of pointer arithmetic is done on uint8_t and then passed onto other APIs which also accept uint8_t *.

However, when replacing uint_8 * with NSMutableData, how do I pointer arithmetic on NSMutableData?

One approach is

  1. convert NSMutableData to uint8_t *.
  2. do pointer arithmetic on uint8_t *.
  3. convert uint8_t * back to NSMutableData and pass it to other APIs.

however, when converting uint8_t * to NSMutableData, I do not have length.

How to solve this?

Old code

func(uint8_t *p);

func2() {
    uint8_t *p; //points to some piece of memory
    func(p+10); //pass  base address+ 10 bytes
}

New Code

func(NSMutableData *p);

func2() {
    NSMutableData *data = [[NSMutableData alloc] 
    initWithLength:size];
    // now, how to pass data + 10 bytes to func
    func(???)
}

Upvotes: 0

Views: 54

Answers (0)

Related Questions