• 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
Re: Accessing buffers in NSData/NSMutableData under garbage collection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing buffers in NSData/NSMutableData under garbage collection


  • Subject: Re: Accessing buffers in NSData/NSMutableData under garbage collection
  • From: Adam P Jenkins <email@hidden>
  • Date: Tue, 19 Feb 2008 00:19:21 -0500

On Feb 19, 2008, at 12:07 AM, mmalc crawford wrote:


On Feb 18, 2008, at 9:00 PM, Adam P Jenkins wrote:

The point of the example was just to show the various positions that __strong can appear in a declaration, but the fact that the example uses int* as the pointer type made me think there is a way to allocate pointers to primitive types that get manage by the GC. However the GC Programming Guide fails to mention how to do this. It would be nice if I could do something like this:

__strong int* ptr = GCableMalloc(numBytes);

and ptr would be managed by the GC. Is there an actual function like GCableMalloc?

<http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcAPI.html >

Cool! I just tried this:

__strong int* ptr = NSAllocateCollectable(1000, 0);

and verified that ptr does get GCed.  I.e. I can write:

NSGarbageCollector *gc = [NSGarbageCollector defaultCollector];

while (1) {
    __strong int* ptr = NSAllocateCollectable(1000, 0);
    [gc collectIfNeeded];
}

and if I build the program that contains this with -fobj-gc-only and run it, the memory usage stays constant. So if you don't need your code to work in non-GC mode, then you can just replace

float *myPointer = [[NSMutableData dataWithLength:size*sizeof(float)] mutableBytes];

with

float *myPointer = NSAllocateCollectable(size*sizeof(float), 0);

and get the same effect.
_______________________________________________


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: Accessing buffers in NSData/NSMutableData under garbage collection
      • From: Adam P Jenkins <email@hidden>
References: 
 >Accessing buffers in NSData/NSMutableData under garbage collection (From: Rick Hoge <email@hidden>)
 >Re: Accessing buffers in NSData/NSMutableData under garbage collection (From: Adam P Jenkins <email@hidden>)
 >Re: Accessing buffers in NSData/NSMutableData under garbage collection (From: mmalc crawford <email@hidden>)

  • Prev by Date: Re: Accessing buffers in NSData/NSMutableData under garbage collection
  • Next by Date: Re: Accessing buffers in NSData/NSMutableData under garbage collection
  • Previous by thread: Re: Accessing buffers in NSData/NSMutableData under garbage collection
  • Next by thread: Re: Accessing buffers in NSData/NSMutableData under garbage collection
  • Index(es):
    • Date
    • Thread