On Thu, Feb 19, 2009 at 1:29 PM, Leo Singer <doc.aron...@gmail.com> wrote:
> I would rather not dynamically allocate that particular array because
> the Cocoa application I am developing is simply a wrapper for a cross
> platform C++ project.  This particular project has to manage a number
> of different resources, including an SQLite database connection, an
> open file, and a serial port device.  In order to keep error handling
> as simple as possible, I have made heavy use of the RIAA pattern.  If
> a serial port error occurs, for example, an exception gets thrown.  As
> a result, the objects representing both the database and the open file
> go out of scope, and their resources are released.
>
> A std::vector would be unsuitable also because in my actual
> application (not the cooked example I sent out) I need to be able to
> manipulate that memory directly.
>
> Some more background information might be helpful.  The application is
> a GUI for a bootloader for Microchip brand DSPs.  The big array in
> question is actually a 256 kb image of the device's program memory.

What you'd rather do is irrelevant: your code has a bug. Allocating
that much memory on the stack simply isn't supported. For example, as
mentioned in another post, some architectures have absolute limits on
stack frame size that you've exceeded here. That you've succeeded now
is mainly due to luck. Your code is still broken, it's just that
you've managed to coax it into working.

There are many ways to automatically manage resources like this,
including using std::vector, writing a small class to wrap your memory
block in the RAII pattern, or simply putting your call to free() in a
finally block. Pick one, and use it, because what you're doing right
now is wrong.

Mike
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to