[Top][All Lists]

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

Re: NSArray: Problem allocating memory on stack on windows

From: Nicola Pero
Subject: Re: NSArray: Problem allocating memory on stack on windows
Date: Thu, 9 Oct 2003 11:40:10 +0100 (BST)

> It looks like that:
> - (id) initWithArray: (NSArray*)array
> {
>   unsigned    c = [array count];
>   id        objects[c];
>   [array getObjects: objects];
>   self = [self initWithObjects: objects count: c];
>   return self;
> }
> with
> id objects[c];
> gcc allocates space on the stack  for c elements using alloca().
> On windows stacksize is limited. So at present when calling initWithArray
> with an array containing more then ~52100 elements stack runs out of space
> and applications crashes (or behaves really silly, depending what gets 
> overwritten)
> The solution here to fix this would be to replace all that dynamic array stuff
> with malloc()/free() calls.

But alloca is much quicker!  We don't want to loose that speed for small
arrays.  I think the solution is:

 if (c < 100)
   use alloca as in the current code
   use malloc()/free() as you suggest

(replace 100 with another reasonable default if you want).

Btw I already met this bug and I'm sure I had fixed it ... I must have
forgotten to commit the patch.

reply via email to

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