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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c3cec4fb2011babb X-Google-Attributes: gid103376,public From: matthew_heaney@acm.org (Matthew Heaney) Subject: Re: Are global or persistent variables in ADA? Date: 1998/05/01 Message-ID: #1/1 X-Deja-AN: 349347032 Content-Transfer-Encoding: 8bit References: <35413389.46570978@news.gatech.edu> <35420cc3.0@news.pacifier.com> Content-Type: text/plain; charset=ISO-8859-1 Organization: Network Intensive Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-05-01T00:00:00+00:00 List-Id: In article <35420cc3.0@news.pacifier.com>, "Steve Doiel" wrote: (start of quote) Fully global variables are declared inside of a package spec (IMHO not a good practice). (end of quote) One idiom where "global" variables do make sense is in the construction of a subsystem, a complex abstraction that comprises several packages, ie package P is end P; private package P.Q is O : T; -- -- O is a "global" variable, shared by children of P. However, it is only -- global with the subsystem rooted at P. end P.Q; with P.Q; package body P.R is ... Q.O ... end P.R; This is a handy technique to use when you have data shared among many modules in a subsystem; perhaps a semaphore or something. Another example of having a global data, not even in a private package, would be a storage pool object. You may decide that all access types in an application will use a non-default storage pool that you've defined, ie package Storage_Pools is type XYZ_Storage_Pool is new Root_Storage_Pool with ...; Pool : Storage_Pool; end Storage_Pools; As a matter a fact, I did something like this in some B-trees I just wrote. One technique I like to use is to pass in a storage pool object to a dynamic memory manager abstraction, ie with System.Storage_Pools; generic System_Storage_Pool : in out System.Storage_Pools.Root_Storage_Pool'Class; package ACL.Trees.Storage.BPlus_Tree.Dynamic_G is pragma Elaborate_Body; type Dynamic_Storage_Pool is new Root_Storage_Pool with private; ... package body ACL.Trees.Storage.BPlus_Tree.Dynamic_G is type Dynamic_Page_Access is access all Page_Base; for Dynamic_Page_Access'Storage_Pool use System_Storage_Pool; And I instantiate it as follows: with ACL.Trees.Storage.BPlus_Tree.Dynamic_G; package BPlus.Storage.Dynamic is new BPlus.Storage.Dynamic_G (BPlus.Storage.Page_Access'Storage_Pool); where I simply use the pool associated with another, already-existing access type. Actually, I do declare a global storage pool object, that I use to instantiate the B-tree iteself; with BPlus.Storage.Dynamic; use BPlus.Storage.Dynamic; package BPlus.Storage_Pools is Pool : Dynamic_Storage_Pool; end; with Ada.Finalization; with ACL.Trees.Storage.BPlus_Tree; generic type B_Tree_Item is private; with function "=" (L, R : B_Tree_Item) return Boolean is <>; ... with package Storage is new ACL.Trees.Storage.BPlus_Tree (B_Tree_Item, B_Tree_Item_Array, B_Tree_Key, B_Tree_Key_Array, Index_Order, Sequence_Order); type B_Tree_Storage_Pool is new Storage.Root_Storage_Pool with private; Storage_Pool : in out B_Tree_Storage_Pool; -- pass in storage pool object ... with ACL.Trees.BPlus_Trees; with BPlus.Searches; use BPlus.Searches; with BPlus.Storage.Dynamic; with BPlus.Storage_Pools; package BPlus.Trees is new ACL.Trees.BPlus_Trees (B_Tree_Item => Integer, B_Tree_Item_Array => Searches.B_Tree_Item_Array, B_Tree_Key => Integer, B_Tree_Key_Array => Searches.B_Tree_Key_Array, Index_Order => Index_Order, Sequence_Order => Sequence_Order, Storage => BPlus.Storage, B_Tree_Storage_Pool => BPlus.Storage.Dynamic.Dynamic_Storage_Pool, Storage_Pool => Storage_Pools.Pool, -- there it is... Get_Key => BPlus.Get_Key); So, from global data isn't necessarily bad, and is often required for declaring static, system-wide data.