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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,927ae253da8bb547 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-30 22:51:29 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news-FFM2.ecrc.net!news.cesnet.cz!crax.cesnet.cz!news.felk.cvut.cz!not-for-mail From: "Sergey Koshcheyev" Newsgroups: comp.lang.ada Subject: Re: Specialization Date: Fri, 31 May 2002 07:41:27 +0200 Organization: Czech Technical University Message-ID: References: <4519e058.0205300909.5bfb317d@posting.google.com> <3CF6CF7D.8000704@worldnet.att.net> NNTP-Posting-Host: m232.dkm.cz X-Trace: ns.felk.cvut.cz 1022823685 14636 62.24.78.232 (31 May 2002 05:41:25 GMT) X-Complaints-To: usenet@ns.felk.cvut.cz NNTP-Posting-Date: Fri, 31 May 2002 05:41:25 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Xref: archiver1.google.com comp.lang.ada:25054 Date: 2002-05-31T07:41:27+02:00 List-Id: "Jim Rogers" wrote in message news:3CF6CF7D.8000704@worldnet.att.net... > Baugereau wrote: > > Ok so this is the difference of philosophy with STL's vector, which is plain > > value-oriented. > > What I dislike here is the lack of locality of the elements, and the need to > > "new" every time I add an element... > > Any comment? > > The difference is that in C++ you "new" the element before you add > it to the vector (in the constructor). This is wrong, if you have a vector in C++ STL, then what is stored are BigObjects, not pointers to them. There are a few tricks that can be used to achieve this ("placement new", and also the fact that it is possible to call object destructors manually). > If you were to dynamically allocate all your objects in Ada, just as > you do in C++, then the container would not need to perform any of the > dynamic allocation. You could simply add references to the objects > just like you do in C++. When using STL containers, you can add a local object into the container, for example, and it will be properly copied. > You will also find that Ada scoping rules are much more strict than C++ > scoping rules. This can influence the way you design your container > package. The scoping rules are not the problem, I think. You can copy the objects, if needed. To imitate C++ in this respect, you just need some way (possibly, a hack) to manually Initialize and Finalize the inserted objects, and ensure that the compiler doesn't also try to do that. Maybe playing with Storage_Pools a little will lead to a solution. Or maybe there is a more Ada-like way, I don't know. Sergey.