On 13 April 2013 00:18, Dmitry Olshansky <dmitry.o...@gmail.com> wrote:
> 12-Apr-2013 18:12, Manu пишет: > >> On 13 April 2013 00:01, Regan Heath <re...@netmail.co.nz >> <mailto:re...@netmail.co.nz>> wrote: >> >> So... >> >> If the GC were to have a hook function for allocation and for free, >> and if when these were in use it would not itself trigger collection. >> >> Then... >> >> Manu could supply hook functions, use the alloc function to supply >> pre-allocated memory, and trigger collection as/when convenient. >> >> >> Believe it or not, I'm not actually a fan of over-complexity. And I'm >> focusing here on totally unnecessary allocations. >> Isn't using the stack where applicable just a whole low easier? That's >> what it's there for. >> > > 'cause nobody can tell you how big it is. This knowledge is only available > to end user and there is still no easy way to "tell" that to the library. > The end result is utterly useless as library can't reliably use stack space. > Filenames, strings, etc have a fairly predictable size. Allocate slightly above that, and fallback to the heap upon overflow. I think it's safe to assume the stack is 'big enough' if you apply some common sense. It measures in the megabytes on PC's, I'm used to working on machines with ~32k stack, I use it aggressively, and I don't tend to run out. In the end if one library thinks it's fine to burn say 32K of stack with > alloca but then it calls into another one that burns another chunk with > alloca and so on untill happily stack overflowing (sometimes, on some > systems at the right time!). Call graphs to calculate this is only > available for the final app. > > Maybe just adding a separate thread-local growable stack for data would > work - at least it wouldn't depend on sheer luck and particular OS settings. If you're saying the stack is a limited resource, therefore it's unsafe to use it, then you might as well argue that calling any function is an unsafe process. Some common sense is required. I wouldn't personally burn more than 1k in a single function, unless I knew it was close to a leaf by design (which many library calls are). 90% of what we're dealing with here are strings, and they tend to measure in the 10s of bytes.