FROM : Clark Cox
DATE : Fri Nov 09 19:33:55 2007
On Nov 9, 2007 9:54 AM, John Stiles <<email_removed>> 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_removed>
DATE : Fri Nov 09 19:33:55 2007
On Nov 9, 2007 9:54 AM, John Stiles <<email_removed>> 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_removed>






Cocoa mail archive

