openexr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Openexr-devel] stack overflow in openexr


From: Pete A.
Subject: RE: [Openexr-devel] stack overflow in openexr
Date: Fri, 10 Mar 2006 21:12:49 -0800

At 03:37 PM 3/8/2006 -0500, Luc-Eric Rousseau wrote:
>We actually had this stack overflow problem on Linux, as the OpenEXR
>code was running a secondary thumbnail thread which didn't have enough
>stack.  We changed it to use the Windows code.  I don't think it's a
>great candidate for a platform define, it just assumes a lot of stack
>is available no matter the plateform.  Ideally it should be changed to
>allocate from the heap after a certain threshold.

The Windows define isn't too great either. With the default options on MS's
linker, the process stack reserve size is 1 meg (which boils down to 16 of
those 64k blocks) but the user can set it much lower (and the person
creating a thread can set it too).

What I do for allocating large blocks on the stack with a fallback is:

bool alloc = false;
void *mem;

__try {
        mem = _alloca(s);
} __except(GetExceptionCode() == STATUS_STACK_OVERFLOW) {
        _resetstkoflw();
        alloc = true;
        mem = malloc(s);
}

...

if (alloc)
        free(mem);

But this is because VC's implementation of alloca sucks. The situation
might be better on other platforms. And I highly recomend the stuff ... be
no more complicated than treating mem as a temp block and doing simple
iterating over it and some other buffer.

Don't worry about _resetstkoflw failing. If it does, you're dangerously
close to legit stack overflow anyway (but the next time it happens, your
thread (process?) terminates).






reply via email to

[Prev in Thread] Current Thread [Next in Thread]