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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed.freenet.de!151.189.20.20.MISMATCH!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada) Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1lr611thktbau$.1dj95z21h7l5v.dlg@40tude.net> <97kpu5gkgo1r$.kc4nx7cxjziw$.dlg@40tude.net> Date: Fri, 11 Mar 2005 16:29:47 +0100 Message-ID: NNTP-Posting-Date: 11 Mar 2005 16:26:27 MET NNTP-Posting-Host: da8e26f2.newsread4.arcor-online.net X-Trace: DXC=[4eA3^\ULgd:35lZDPnnTl:ejgIfPPlddjW\KbG]kaMhGSi?jHD8GO`FVdNEhFN_ac[6LHn;2LCVn7enW;^6ZC`d<=9bOTW=MNn X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:9139 comp.lang.c++:45142 comp.realtime:1280 comp.software-eng:4846 Date: 2005-03-11T16:26:27+01:00 List-Id: On Fri, 11 Mar 2005 14:28:26 +0100, Peter Koch Larsen wrote: > "Dmitry A. Kazakov" skrev i en meddelelse > news:qehxli3ofpnd.1n3ma1ro7drgt$.dlg@40tude.net... >> On Fri, 11 Mar 2005 10:42:51 +0100, Peter Koch Larsen wrote: >> >>> "Dmitry A. Kazakov" skrev i en meddelelse >>> news:97kpu5gkgo1r$.kc4nx7cxjziw$.dlg@40tude.net... >> >>>>>> 2. C++ is unable to allocate objects of indefinite size on the stack. >>>>> >>>>> Well, we have alloca() for this ;) >>>> >>>> Try to return such object from a function. Ada can >>>> >>>> declare >>>> Object : T'Class := Read_It_From_File; >>>> >>>> Here neither the specific type, nor the size of the object are known at >>>> compile time. Another example: >>>> >>>> declare >>>> Line : String := Read_Source_Line (File); >>>> >>>> Or even: >>>> >>>> Put_Line (Read_Source_Line (File)); >>> >>> The solution is simple here - just allocate your memory on the heap. >> >> Heap is far slower than stack. Also stack is much safer, because objects >> allocated on the stack have visible scopes, as compared to adventures with >> pointers. Do you want to add one more indirection layer - smart pointers, >> or do it even worse by using GC? > > I believed the object might have to be returned? Read the post once again. > If this is so, you can not allocate it on the stack without having to copy > when you return the object. Surely the copy must be more expensive than the > allocation? The compiler can use multiple stacks so that arguments and the result might be allocated on different stacks. > Ordinary heap-based speed is not so slow and if you need to get the last > cpu-cycle away, you can simply use an arena for your allocation. Yes, some Ada compilers would probably use discontiguous object representation and arenas for variable parts. The difference is that it is still not the global heap. And it is controlled by the compiler which exactly knows the scope of objects. > Also you will of course use a smart pointer in the situation above. A C++ > programmer with respect for himself only rarely uses new without putting the > result in some kind of smart pointer. Personally, I do not remember when i > did that last. I'd be happy if all C++ programmers would be ready and willing to compensate deficiencies of the language through more careful and thoughtful design. Actually, we are doing a lot of developing in C++, and due to my job responsibilities time to time I have to review C++ code... -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de