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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham 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!news1.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!news100.image.dk!news000.worldonline.dk.POSTED!not-for-mail From: "Peter Koch Larsen" Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng 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> Subject: Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: Date: Fri, 11 Mar 2005 14:28:26 +0100 NNTP-Posting-Host: 62.79.147.244 X-Complaints-To: news-abuse@wol.dk X-Trace: news000.worldonline.dk 1110547705 62.79.147.244 (Fri, 11 Mar 2005 14:28:25 MET) NNTP-Posting-Date: Fri, 11 Mar 2005 14:28:25 MET Organization: Customer of Tiscali A/S Xref: g2news1.google.com comp.lang.ada:9129 comp.lang.c++:45125 comp.realtime:1272 comp.software-eng:4838 Date: 2005-03-11T14:28:26+01:00 List-Id: "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? 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. 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. /Peter > > -- > Regards, > Dmitry A. Kazakov > http://www.dmitry-kazakov.de