Benjamin Lambert <benlambert@...> writes:
> Hi there,
> I've been a bit puzzled the last few days about a memory fault I've
> been getting. It turns out to be the control stack getting exhausted,
> but the error I have been getting is simply a "memory fault". I
> thought I should share this, in case it's possible to print that the
> error is a control stack problem, rather than the more vague "memory
> fault" error.
> It took me a while of adding numerous print-outs to my code to find the error, but it turned out to be coming from this form, which appends a list of lists:
> (apply 'append list-of-lists)
> Before I discovered that it was a control stack size issue (which SBCL on my Mac is now showing), I tried this instead, which doesn't cause the error:
> (apply 'concatenate 'list list-of-lists)
> The list of lists is length 100,000. So, it's easy to reproduce this with (or increase the 100,000 to be big enough to fill the control stack):
> (apply 'append (make-list 100000 :initial-element '()))
> It makes sense that this would exhaust the stack. (I am aware of how to increase the stack size with --control-stack-size).
> On Linux (and sometimes on Mac), I get the error:
> CORRUPTION WARNING in SBCL pid 16130(tid 140737353885424):
> Memory fault at f293d040 (pc=0x100050d041, sp=0x7ffff293d040)
> The integrity of this image is possibly compromised.
> Previously, I was getting the same error on Mac, but now I'm getting a control stack exhausted error:
> fatal error encountered in SBCL pid 91825:
> Control stack exhausted
> This is SBCL 1.0.55 on Mac, and 1.1.0 on Linux (x86-64).
> So, I suppose my questions are:
> 1) Does it make sense that APPEND exhausts the stack, but CONCATENATE doesn't?
> 2) Is it possible to catch the error and report it as "control stack exhausted" rather than simply as a "memory fault"?
You shouldn't ever use APPLY on an arbitrary number of arguments. Use
(reduce #'append list-of-lists :from-end t)
(from-end helps minimize consing, because append always has to copy the
first list, that way the first list doesn't become larger with each
With best regards, Stas.