NSData, CFData maximum length question
NSData, CFData maximum length question
- Subject: NSData, CFData maximum length question
- From: Grandinetti Philip <email@hidden>
- Date: Wed, 21 Mar 2012 21:00:36 -0400
I am confused about different behavior I'm seeing with CFData and NSData. If I create a new project in XCode 4.3.1 as a Core Foundation command line tool, and enter the code below...
#include <CoreFoundation/CoreFoundation.h>
int main(int argc, const char * argv[])
{
CFIndex length = (1ULL << 30);
fprintf(stderr, "length = %ld\n",length);
CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0);
CFDataSetLength(data, length);
}
it crashes with the error message below:
length = 1073741824
test(2463) malloc: *** mmap(size=18446744071562067968) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
2012-03-21 20:55:35.292 test[2463:403] Attempt to allocate -2147483648 bytes for NS/CFData failed. Maximum size: 4398046511103
Whereas, if I create a new project as a Foundation command line tool, and enter the code below, it runs without errors.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
CFIndex length = (1ULL << 30);
fprintf(stderr, "length = %ld\n",length);
NSMutableData *data = [NSMutableData dataWithCapacity:0];
[data setLength:length];
}
return 0;
}
Both Xcode projects are created (the default) as 64 bit. So, why does the Core Foundation CFDataSetLength get the wrong length?
I've searched the 64 bit transition guides and can't find any answers. Any suggestions would be greatly appreciated.
Thanks,
Philip
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden