POV-Ray : Newsgroups : povray.off-topic : Teach yourself C++ in 21 days : Re: Days 5- Server Time
29 Jul 2024 10:22:51 EDT (-0400)
  Re: Days 5-  
From: Warp
Date: 28 Apr 2012 13:14:11
Message: <4f9c2563@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> On 4/28/2012 9:52, Warp wrote:
> > level were 50,

> I understand your argument. I'm unconvinced that you're (a) not already 40 
> levels of stack deep when you get invoked, and (b) know what your stack 
> recursion depth can be.

  My point is that you are not going to get even close to 50. Perhaps
something like 20.

  If your stack can't hold hundreds of recursive function calls, then
you should upgrade your computer to the new millenium.

> Maybe I'm just used to working on machines with actual limited address space 
> and RAM. 50 levels of recursion sounds like a lot of stack space used, to me.

  What? Even if each function call took like a kilobyte of space (which is
quite a lot for one single function call), it would still be just 50 kB.
I think stack sizes are counted in megabytes in modern systems.

>  >   It's highly unusual to require enormous amounts of stack on one single
> function call,

> I would think that depends on the program. If you're making an image of your 
> input data for each level, you're

doing it wrong. (If for nothing else, then because it increases the
computational complexity of your algorithm by a factor of n, which is quite
a lot. Eg. a fast O(n log n) algorithm becomes a crawling O(n^2 log n).
Not to talk about if the original algorithm was eg. O(n^2) to begin with...)

> >> Why does C++ limit the depth of template instantiation required to 17
> >> levels, or whatever it is?
> >
> >    Never heard of such a limit.

> IIRC, template function nesting is only required to be supported to some 
> realtively small depth.

  I suppose the standard probably as a minimum recommended amount (like
it has for many other things, like the length of variable names). However,
if you surpass that limit your program won't even compile, so it's not
a question of running out of memory when running the program. (And most
C++ compilers have an option to increase the space dedicated to type
names.)

  Consider that some projects use template metaprogramming quite
extensively, and the internal type names that result from it can be
quite large (we are talking about thousands and thousands of characters).
Most C++ programs don't use type names that long.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.