comp.lang.ada
 help / color / mirror / Atom feed
From: "Baugereau" <baugereau@ifrance.kom>
Subject: Re: Specialization
Date: Thu, 30 May 2002 19:29:53 +0200
Date: 2002-05-30T17:27:50+00:00	[thread overview]
Message-ID: <ad5nem$fhb$1@wanadoo.fr> (raw)
In-Reply-To: 4519e058.0205300909.5bfb317d@posting.google.com

> "Baugereau" <baugereau@ifrance.kom> wrote in message
news:<ad56du$pp4$1@wanadoo.fr>...
> > For instance, when I empty the container, I want to Finalize all the
> > elements if they are Controlled, and do nothing if not.
>
> Why wouldn't that happen automaticly? If you want to *manually*
> control finalization, you probably shouldn't be using controlled
> types.

I have this interface in my package (I snipped)


with Ada.Finalization;
use Ada.Finalization;
generic
type ELEMENT is private;
package Vector is
Default_Reserved : constant NATURAL := 32;
Growth : constant NATURAL := 32;
type ELEMENTPTR is access all ELEMENT;
type ELEMENTS is array(NATURAL range <>) of aliased ELEMENT;
type ELEMENTSPTR is access ELEMENTS;
type VECTOR is new CONTROLLED with record
   Size : NATURAL;
   Reserved : NATURAL;
   Data : ELEMENTSPTR;
end record;

-- Controlled type
procedure Initialize (obj : in out VECTOR);
procedure Finalize (obj : in out VECTOR);
procedure Adjust (obj : in out VECTOR);

-- Custom
function Get (obj : in VECTOR; index : in NATURAL) return ELEMENTPTR;
function Get (obj : in VECTOR; index : in NATURAL) return ELEMENT;
procedure Push_Back (obj : in out VECTOR; elt : in ELEMENT);
procedure Empty (obj : in out VECTOR);
procedure Erase (obj : in out VECTOR; first : in NATURAL; last : in
NATURAL);
private
procedure Realloc (obj : in out VECTOR; new_reserved : in POSITIVE);
end Vector;


the goal is to have Data as a raw storage of ELEMENTs that I can extend when
I Push_Back elements in the VECTOR...
Data has Reserved elements but only Size elements are meaningful.
And if I push_back a lot of elements, I don't want to realloc the storage
each time, so I make it grow linearly (for now).

Then when I erase, reserved must stay the same, size should become 0, and
objects in the storage should be finalized if they are not trivial.
Is it clear this time? Sorry I'm not a native speaker :)

Is this inherently flawed?
Should I not bother with growing Data by myself? I don't think so, because I
think "new" is costly (it is just a belief :) )






  reply	other threads:[~2002-05-30 17:29 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-30 12:39 Specialization Baugereau
2002-05-30 17:09 ` Specialization Ted Dennison
2002-05-30 17:29   ` Baugereau [this message]
2002-05-30 19:20     ` Specialization Stephen Leake
2002-05-30 19:48       ` Specialization Baugereau
2002-05-31  1:18         ` Specialization Jim Rogers
2002-05-31  5:41           ` Specialization Sergey Koshcheyev
2002-05-31 11:36             ` Specialization Baugereau
2002-05-31 14:08             ` Specialization Jim Rogers
2002-05-31 16:45               ` Specialization Hyman Rosen
2002-05-31 17:05               ` Specialization Sergey Koshcheyev
2002-05-31 17:40                 ` Specialization Hyman Rosen
2002-05-31 20:04                   ` Specialization Sergey Koshcheyev
2002-05-31 21:25                     ` Specialization Hyman Rosen
2002-05-31 13:27         ` Specialization Stephen Leake
2002-05-31 19:46           ` Specialization Simon Wright
2002-06-01 15:30             ` Specialization Stephen Leake
2002-05-31 19:44   ` Specialization Simon Wright
2002-06-01 15:25     ` Specialization Stephen Leake
2002-06-01 17:12       ` Specialization Simon Wright
2002-06-01 19:50         ` Specialization Stephen Leake
2002-05-30 17:46 ` Specialization Toshitaka Kumano
replies disabled

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