• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: zeroing out unused bytes from NSData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: zeroing out unused bytes from NSData


  • Subject: Re: zeroing out unused bytes from NSData
  • From: Phill Kelley <email@hidden>
  • Date: Thu, 17 Apr 2003 08:13:22 +1000

At 19:26 +0200 16/04/2003, Salanki Benjamin wrote:
>I have an NSData structure that has unused bytes at the end. How can I
>zero out the unused bytes at the end so that my NSDatat will have only
>used bytes in it?

It is my understanding that structures are zeroed when they are allocated,
so your unused bytes should already be zero.

If your question really is, "if I have an NSData structure of length N of
which only the first M bytes are in use and I want to throw away the unused
bytes at the end then (a) use an NSMutableData object and (b) send it the
setLength message. Example:


#define N 16
#define M 8

// allocate the structure (autoreleased)
NSMutableData* buffer = [NSMutableData dataWithLength:N];

NSLog(@"%@",buffer);

// reduce its length
[buffer setLength:M];

NSLog(@"%@",buffer);


The result from the two NSLog messages will be:

<00000000 00000000 00000000 00000000 >
<00000000 00000000 >

Not only does this show that the structure is initialized to zero but that
you can reduce its length.


PK
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >zeroing out unused bytes from NSData (From: Salánki Benjámin <email@hidden>)

  • Prev by Date: Unix Network Programming by Stevens && Mac OS X...
  • Next by Date: Re: NSTableView and Scrollbars
  • Previous by thread: Re: zeroing out unused bytes from NSData
  • Next by thread: import PB project
  • Index(es):
    • Date
    • Thread