Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A coding pattern that does not work under Garbage Collection



On Nov 9, 2007 9:54 AM, John Stiles <email@hidden> wrote:
> If you aren't averse to ObjC++, there's always the traditional C++
> solution for a block of memory that has a controlled lifetime:
>
>         vector<float> myData(size);
>         float *myPointer = &myData[0]; // or just use myData directly, it
> will work the same as a C array in the majority of cases
>
> Then myData should last until it falls out of scope. This is easier
> than malloc because you don't have to worry about edge cases where
> you fail to free it properly (e.g. calling return in the middle of a
> function).
>
> Only thing I'm not sure about—if you raise an ObjC exception, I don't
> know if myData would be leaked. Not sure how well ObjC++ exceptions
> handle C++ cleanup.

In 32-bit, it isn't handled at all (you'll have to catch the Obj-C
exceptions, destroy the vector yourself, and rethrow the exception).
In 64-bit, Obj-C exceptions *are* C++ exceptions (and vice-versa), so
all is well (all the normal C++ stack unwinding/destructor calling
goodness happens)

-- 
Clark S. Cox III
email@hidden
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >A coding pattern that does not work under Garbage Collection (From: Rick Hoge <email@hidden>)
 >Re: A coding pattern that does not work under Garbage Collection (From: John Stiles <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.