comp.lang.ada
 help / color / mirror / Atom feed
* How to do placement new in Ada
@ 2003-01-22  1:13 Victor Porton
  2003-01-22 11:20 ` Lutz Donnerhacke
  0 siblings, 1 reply; 2+ messages in thread
From: Victor Porton @ 2003-01-22  1:13 UTC (permalink / 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...



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to do placement new in Ada
  2003-01-22  1:13 How to do placement new in Ada Victor Porton
@ 2003-01-22 11:20 ` Lutz Donnerhacke
  0 siblings, 0 replies; 2+ messages in thread
From: Lutz Donnerhacke @ 2003-01-22 11:20 UTC (permalink / raw)


* Victor Porton wrote:
> 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.

If you need a global variable (you do), using a global variable is not bad.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-01-22 11:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-22  1:13 How to do placement new in Ada Victor Porton
2003-01-22 11:20 ` Lutz Donnerhacke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox