Re: Accessing buffers in NSData/NSMutableData under garbage collection
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:00:08 -0500
On Feb 18, 2008, at 5:21 PM, Rick Hoge wrote:
One of the patterns that breaks badly is the following type of thing:
float *myPointer = [[NSMutableData
dataWithLength:size*sizeof(float)] mutableBytes];
It makes sense that this wouldn't work, even if you declare myPointer
to be __strong. NSMutableData was written before GC was introduced,
so the only sensible way to implement it would have been for the
NSMutableData object to free the contained data.
However, it seems like there should be a way to have pointers to
primitive types that are managed by GC. The Garbage Collection
Programming Guide has this example of the use of __strong, in the
Garbage Collection API section:
@interface MyClass {
__strong int *ptr1;
int * __strong ptr2;
int __strong * ptr3;
}
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?
_______________________________________________
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