NSMutableData initWithCapacity
- (id)initWithCapacity:(NSUInteger)capacity
Parameters
capacity
The number of bytes the data object can initially contain.
Return Value
An initialized NSMutableData object capable of holding capacity bytes.
Discussion of [NSMutableData initWithCapacity]
This method doesn’t necessarily allocate the requested memory right away. Mutable data objects allocate additional memory as needed, so aNumItems simply establishes the object’s initial capacity. When it does allocate the initial memory, though, it allocates the specified amount. This method sets the length of the data object to 0.
If the capacity specified in aNumItems is greater than four memory pages in size, this method may round the amount of requested memory up to the nearest full page.
NSMutableData initWithCapacity example.
self.receiveData = [[[NSMutableData alloc] initWithCapacity:0] autorelease];
OR
NSMutableData * myData = [[NSMutableData alloc] initWithCapacity:0];
self.receiveData = myData ;
[myData release];
myData = nil ;
OR
NSMutableData * myData = [[NSMutableData alloc] initWithCapacity:0];
self.receiveData = myData ;
[myData release];
myData = nil ;
Example of [NSMutableData initWithCapacity].
-(void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
if (data==nil) {
data = [[NSMutableData alloc] initWithCapacity:2048];
}
[data appendData:incrementalData];
}
NSMutableData initWithCapacity example.
-(void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
if (data==nil) { data = [[NSMutableData alloc] initWithCapacity:2048]; }
[data appendData:incrementalData];
}
if (data==nil) { data = [[NSMutableData alloc] initWithCapacity:2048]; }
[data appendData:incrementalData];
}