From: porton@ex-code.com (Victor Porton)
Subject: How to do placement new in Ada
Date: Wed, 22 Jan 2003 06:13:47 +0500
Date: 2003-01-22T01:14:37+00:00 [thread overview]
Message-ID: <3e2df07d$0$33931$bed64819@news.gradwell.net> (raw)
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...
next reply other threads:[~2003-01-22 1:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-22 1:13 Victor Porton [this message]
2003-01-22 11:20 ` How to do placement new in Ada Lutz Donnerhacke
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox