• 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
NSData, CFData maximum length question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSData, CFData maximum length question
      • From: Seth Willits <email@hidden>
  • Prev by Date: Re: How to get max size of view according to constraints?
  • Next by Date: Re: How to get max size of view according to constraints?
  • Previous by thread: Re: makeObjectsPerformSelector on a sub class
  • Next by thread: Re: NSData, CFData maximum length question
  • Index(es):
    • Date
    • Thread