• 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
Custom zones...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom zones...


  • Subject: Custom zones...
  • From: "charlie" <email@hidden>
  • Date: Tue, 10 Aug 2010 04:18:21 +0000


Having trouble getting objects to use a specific zone.

The following test code snippet demonstrates the problem I'm having:

	NSZone * zone = NSCreateZone(vm_page_size * 2, vm_page_size, YES);
	if (zone)
	{
		NSSetZoneName(zone, @"IN THE ZONE!!!");

char * cstring = (char *)NSZoneCalloc(zone, 50, 1);
if (cstring)
{
sprintf(cstring, "abc!!");
NSLog(@" zone = %p", (void *)zone);
NSLog(@"cstring = %p", (void *)cstring);
NSLog(@" end = %p", (void *)(((unsigned char *)cstring)+(vm_page_size * 2)));

NSZone * _czone = NSZoneFromPointer((void *)cstring);
if (_czone)
{
NSLog(@"cstring.zone name = %@", NSZoneName(_czone));
}

}

NSString * string = [[NSString allocWithZone:zone] initWithFormat:@"abc!!!"];
if (string)
{
NSLog(@" zone = %p", (void *)zone);
NSLog(@"string = %p", (void *)string);
NSLog(@" end = %p", (void *)(((unsigned char *)string)+(vm_page_size * 2)));

NSZone * _zone = NSZoneFromPointer((void *)string);
if (_zone)
{
NSLog(@"string.zone name = %@", NSZoneName(_zone));
}
}
}



... this code generates the following output:

2010-08-09 22:06:22.765 zonetest[24440:a0f] zone = 0x114658000
2010-08-09 22:06:22.768 zonetest[24440:a0f] cstring = 0x114b00010
2010-08-09 22:06:22.769 zonetest[24440:a0f] end = 0x114b02010
2010-08-09 22:06:22.770 zonetest[24440:a0f] cstring.zone name = IN THE ZONE!!!
2010-08-09 22:06:22.770 zonetest[24440:a0f] zone = 0x114658000
2010-08-09 22:06:22.771 zonetest[24440:a0f] string = 0x10010ab30
2010-08-09 22:06:22.771 zonetest[24440:a0f] end = 0x10010cb30
2010-08-09 22:06:22.772 zonetest[24440:a0f] string.zone name = DefaultMallocZone



As you can see, the c string is successfully allocated from space in the custom zone. But the NSString object is allocated from the default zone, despite having called +[NSObject allocWithZone:].


Anyone know the trick to this?

Thanks.

Chuck






_______________________________________________

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: Custom zones...
      • From: Alastair Houghton <email@hidden>
    • Re: Custom zones...
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: calling a function in one class from another
  • Next by Date: Re: help with linking combo boxes
  • Previous by thread: Re: NStoolbarItem, custom view, setAction:
  • Next by thread: Re: Custom zones...
  • Index(es):
    • Date
    • Thread