• 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
Maximum size of an NSMutableData object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Maximum size of an NSMutableData object?


  • Subject: Maximum size of an NSMutableData object?
  • From: Phill Kelley <email@hidden>
  • Date: Wed, 4 Dec 2002 13:30:15 +1100

I have a question as to whether there is any relationship between the
amount of physical RAM installed in a machine and the maximum size of an
NSMutableData object that can be allocated.

A short test program follows (Project Builder, New Project, Foundation
Tool, then paste the following into main.m):

#import <Foundation/Foundation.h>


void test (unsigned capacity)
{

NSMutableData* mutableData;

NSLog(@"About to allocate %d bytes",capacity);
mutableData = [[NSMutableData alloc] initWithCapacity:capacity];
[mutableData setLength:capacity];
NSLog(@"NSMutableData size = %d bytes",[mutableData length]);
[mutableData release];

}


int main (int argc, const char * argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

// initialize capacity to one byte less than 1 gigabyte
unsigned physicalMemory = NSRealMemoryAvailable();

// report amount of physical memory installed
NSLog(@"Physical RAM installed = %d bytes",physicalMemory);

// attempt to allocate a structure of one byte less than twice
// the amount of physical memory
test(2*physicalMemory-1);

// now a structure of twice physical memory
test(2*physicalMemory);

[pool release];
return 0;

}


When I run this program, I see the following results:

2002-12-04 12:55:31.832 MemoryTest[1131] Physical RAM installed = 536870912
bytes
2002-12-04 12:55:31.832 MemoryTest[1131] About to allocate 1073741823 bytes
2002-12-04 12:55:56.942 MemoryTest[1131] NSMutableData size = 1073741823 bytes
2002-12-04 12:55:57.248 MemoryTest[1131] About to allocate 1073741824 bytes
2002-12-04 12:55:57.292 MemoryTest[1131] *** Uncaught exception:
<NSInvalidArgumentException> *** -[NSConcreteMutableData
initWithCapacity:]: absurd capacity: 1073741824

MemoryTest has exited due to signal 5 (SIGTRAP).


Does anyone know whether one gigabyte (1073741824) is an absolute Mac OS
X-wide limit for the size of an NSMutableData object or if the limit is
dependent upon the amount of physical RAM I have installed?

To put the question another way, I have 512MB in my machine now but if I
doubled my physical RAM to 1GB, would the maximum size of an NSMutableData
object become 2GB-1 bytes, or would it remain at 1GB-1 bytes?


Regards & thanks, Phill
_______________________________________________
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.

  • Follow-Ups:
    • Re: Maximum size of an NSMutableData object?
      • From: Dietrich Epp <email@hidden>
  • Prev by Date: Re: Printing many, many pages efficiently
  • Next by Date: The GIF conspiracy
  • Previous by thread: Re: NSTask vs. popen vs. System
  • Next by thread: Re: Maximum size of an NSMutableData object?
  • Index(es):
    • Date
    • Thread