comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: Compiler default initialization of array types
Date: Fri, 18 Oct 2002 09:36:32 -0400
Date: 2002-10-18T09:36:32-04:00	[thread overview]
Message-ID: <ur03j1c0ks1te9@corp.supernews.com> (raw)
In-Reply-To: wcc3cr4vcti.fsf@shell01.TheWorld.com


"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message
news:wcc3cr4vcti.fsf@shell01.TheWorld.com...
>
> I have written code where there were lots of giant arrays of pointers,
> inside a record with another component indicating how many are valid.
> Something like:
>
>     type T is
>         record
>             Last: Natural := 0;
>             Pointers: Pointer_Array(1..Big_Number);
>
> Typically, objects of type T would use just a few pointers -- like Last
> might be 3 or 4, but very unusual for it to be 1000 or 1_000_000.
>
> It turned out that initializing all those unused pointers to null was a
> serious performance problem.  So I cheated: I declared the array as an
> array of integers (where the integer type was chosen to be the same size
> as a pointer), and used unchecked_conversion.

I've been thinking about this same issue while writing the Charles vector
type.  The STL plays tricks like you mention above, but it's not obvious how
to do this in Ada (portably, anyway).

One possibility is to declare a special storage pool type that works off the
internal array, and return the address of the array component that needs
initialization or finalization.  This would give you the rough equivalent of
placement new and explicit dtor invokation.

Something like this?

generic
   type Element_Type is private;
package GP is
...
private
   subtype Component_Subtype is
      Storage_Array (1 .. Element_Type'Max_Size_In_Storage_Elements);

   type Element_Array is
     array (Positive range <>) of aliased Component_Subtype;
...

Hmmm, that just might work.  Any possibility that
Max_Size_In_Storage_Elements will return a "large" value, even for a generic
actual type that is definite?

The only issue is that a storage pool is limited, which would make the
container type containing the pool limited too.  Maybe you could declare a
pool object in the body, but then you'd loose Preelaborate categorization,
and probably have to start worrying about synchronization issues.  Oh, the
joys of library design....









  parent reply	other threads:[~2002-10-18 13:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-17 12:55 Compiler default initialization of array types Sebastian
2002-10-17 13:10 ` Lutz Donnerhacke
2002-10-17 22:39   ` Peter Richtmyer
2002-10-17 13:42 ` Matthew Heaney
2002-10-17 23:57   ` Robert A Duff
2002-10-18  9:50     ` Larry Kilgallen
2002-10-18 14:40       ` Robert A Duff
2002-10-18 15:04         ` Larry Kilgallen
2002-10-18 13:36     ` Matthew Heaney [this message]
2002-10-18 15:28     ` Wes Groleau
  -- strict thread matches above, loose matches on Subject: below --
2002-10-17 14:23 Grein, Christoph
replies disabled

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