Re: zeroing out unused bytes from NSData
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.