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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b32f0a7e92026a28,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-21 17:14:37 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!feed.news.nacamar.de!newsfeed.vmunix.org!news-peer.gradwell.net!not-for-mail Newsgroups: comp.lang.ada From: porton@ex-code.com (Victor Porton) Date: Wed, 22 Jan 2003 06:13:47 +0500 Organization: Extreme Code Software (http://ex-code.com) Subject: How to do placement new in Ada Mime-Version: 1.0 X-Newsreader: knews 1.0b.1 Content-Type: text/plain; charset=us-ascii X-URL: http://www.ex-code.com/ Message-ID: <3e2df07d$0$33931$bed64819@news.gradwell.net> NNTP-Posting-Date: 22 Jan 2003 01:14:37 GMT NNTP-Posting-Host: 195.149.39.13 X-Trace: 1043198077 news.gradwell.net 33931 mail2news/195.149.39.13 X-Complaints-To: news-abuse@gradwell.net Xref: archiver1.google.com comp.lang.ada:33328 Date: 2003-01-22T01:14:37+00:00 List-Id: I want something like C++'ish placement new in Ada: generic type Object is limited private; -- To simplify the task you can exclude "limited". procedure Placement_New(Addr: System.Address); -- This should initialize the memory region -- Addr..Addr+Object'Storage_Size-1 -- the same way as if a variable would be declared so: -- Var: Object; for Var'Address use Addr; -- but with the difference that it would be not finalized -- when goes out-of-scope. I tried to do this with: 1. "for XXX'Address use ...;" This does not work as it is deallocated when goes out-of-scope. 2. With special allocator and 'Storage_Pool attribute. This does not work as for every allocation we need separate allocator instance (because addresses are different) and consequencely a separate access type which is local. So we fall into the same pit: When goes out-of-scope the allocated storage is automatically reclaimed (e.g. errant Finalize is called). Well, it is possible using a global variable of a special storage pool type and setting the address at which such the allocator would allocate before every allocation (using a global field in the allocator), but we know that global variables are bad. P.S. Now I have funny idea of using special allocators which themselves are dynamically allocated by a special completely fake (not allocating anything at all in fact) allocator...