From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5d71,d275ffeffdf83655 X-Google-Attributes: gidf5d71,public X-Google-Thread: 103376,d275ffeffdf83655 X-Google-Attributes: gid103376,public X-Google-Thread: 146b77,d275ffeffdf83655 X-Google-Attributes: gid146b77,public X-Google-Thread: 1108a1,d275ffeffdf83655 X-Google-Attributes: gid1108a1,public X-Google-Thread: f849b,d275ffeffdf83655 X-Google-Attributes: gidf849b,public X-Google-Thread: 115aec,d275ffeffdf83655 X-Google-Attributes: gid115aec,public X-Google-Thread: 101b33,d275ffeffdf83655 X-Google-Attributes: gid101b33,public X-Google-Thread: 109fba,d275ffeffdf83655 X-Google-Attributes: gid109fba,public From: "Martijn Lievaart" Subject: Dynamic memory? (was Re: Ada vs C++ vs Java) Date: 1999/01/18 Message-ID: <77vclp$rme@news3.euro.net>#1/1 X-Deja-AN: 433982190 References: <369C1F31.AE5AF7EF@concentric.net> <369DDDC3.FDE09999@sea.ericsson.se> <369e309a.32671759@news.demon.co.uk> <369F0592.94F9DDDA@dresdner-bank.com> <77pnr4$ch3$1@newnews.global.net.uk> <36a3281a.11980677@news.demon.co.uk> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Organization: EuroNet Internet Newsgroups: comp.lang.ada,comp.lang.c++,comp.vxworks,comp.lang.java,comp.java.advocacy,comp.realtime,comp.arch.embedded,comp.object,comp.lang.java.programmer Date: 1999-01-18T00:00:00+00:00 List-Id: John Birch wrote in message <36a3281a.11980677@news.demon.co.uk>... >On Sun, 17 Jan 1999 06:53:08 GMT, Matthew Heaney > wrote: > >>"John Birch" writes: >> >>> The reason IMHO is that C++ inherently relies upon dynamic memory >>> allocation! It's really as simple as that. If you can show me how to >>> calculate the maximum amount of memory required by a given C++ program then >>> I'll reconsider, until then I'll continue using C without malloc and free! >> >>When does C++ "inherently rely upon dynamic memory allocation"? >> >OK, say I have the following; > >Complex one (1), Complex two (2), Complex three (3), Complex four (4); > >Complex Sum; > >Sum = one + two + three + four; > >If Complex is a class with an overloaded + operator, I get temporary >objects generated (possibly at the compiler's option) in the above >statement. Since it can be written as; > >Sum = operator + (operator + (operator +(one, two), three), four); > >Now where do these temporary objects get created? On the stack, or on >the heap. > >In C the stack size (without recursion) can never grow beyond the >maximum of the total of the stack requirements of all of the functions >defined. > >How do I calculate the potential stack size in C++? > >There is inherent dynamic memory allocation going on here, it is >irrelevant whether it is satck or heap. I (the coder) did not >explicitly allocate memory, the language (or rather the implementation >of the language) did. > Well, you can take it to far! If you count this as dynamic memory allocation, you cannot use any one function as it will dynamically allocate a stackframe (hint: the "allocated memory" refered to above is also in the stack frame). Gets kinda hard to write a C program without any function! Martijn -- My reply-to address is intentionally set to /dev/null reply to mlievaart at orion in nl