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,3885b7fd66a1db28 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-28 22:07:49 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!nntp-relay.ihug.net!ihug.co.nz!west.cox.net!cox.net!cyclone1.gnilink.net!spamfinder.gnilink.net!nwrddc03.gnilink.net.POSTED!53ab2750!not-for-mail From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3a) Gecko/20021210 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Why is Ada a good choice for an ambitious beginner to programming References: <5ad0dd8a.0212210251.63b87aba@posting.google.com> <5ad0dd8a.0212230352.11f8b886@posting.google.com> <5ad0dd8a.0212231215.6ae81bf7@posting.google.com> <7WdO9.115704$4W1.35198@nwrddc02.gnilink.net> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sun, 29 Dec 2002 06:07:49 GMT NNTP-Posting-Host: 162.83.249.78 X-Complaints-To: abuse@verizon.net X-Trace: nwrddc03.gnilink.net 1041142069 162.83.249.78 (Sun, 29 Dec 2002 01:07:49 EST) NNTP-Posting-Date: Sun, 29 Dec 2002 01:07:49 EST Xref: archiver1.google.com comp.lang.ada:32374 Date: 2002-12-29T06:07:49+00:00 List-Id: Bill Findlay wrote: > ... specifically to create local (i.e. not heap) dynamic arrays. > As I said, I don't know whether C++ beginners need to do that. I've never actually seen placement new used for this. After all, in C++, how would you get the local storage in which to place the object? There are two common uses for placement new that I'm aware of. One looks like new(nothrow)Type, and selects a storage allocator which returns null if it can not allocate the requested memory (the default one throws an exception when this happens). The other looks like new(pointer)Type, and that allocator simply returns its argument, which must be properly aligned and sized storage for holding the object (and this latter one is like Ada's for x'address use). That second form decouples allocation of storage from initialization of objects. It's not used often in user code, but figures heavily in some library implementation code. For example, std::vector maintains a size and a capacity. The former represents the number of elements being held in the vector, and the latter represents the amount of storage available. While capacity exceeds storage, new elements are appended to the vector by using placement new to put them in the unused space.