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,1d485db3760413be X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-18 06:36:39 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!news-out.cwix.com!newsfeed.cwix.com!newsfeed1.cidera.com!Cidera!telocity-west!TELOCITY!sn-xit-03!sn-xit-06!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: Compiler default initialization of array types Date: Fri, 18 Oct 2002 09:36:32 -0400 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:29901 Date: 2002-10-18T09:36:32-04:00 List-Id: "Robert A Duff" 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....