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,88f482297d40dac1 X-Google-Attributes: gid103376,public From: brennanw@wanda.vf.pond.com (Bill Brennan) Subject: Re: Question about new allocator Date: 1997/02/11 Message-ID: <5dqeee$2qn@wanda.vf.pond.com>#1/1 X-Deja-AN: 218071094 references: organization: Fishnet - Philly's premier Internet provider newsgroups: comp.lang.ada Date: 1997-02-11T00:00:00+00:00 List-Id: In article , wrote: >I am wondering if the new allocator will return NULL if the heap is full >as it does in C++ or if Ada has some other convention. I am new to Ada >and can't seem to find this discussed anywhere. The context I am >thinking about this is in trying to write a Boolean type IsFull function >for a Queue package. If you can help with a suggestion, please email to >jsherman@asu.edu. Thanks in advance. The method in which Ada communicates that the heap is exahausted is to raise the Storage_Error exception. Your IsFull function would look something like this: function IsFull( Queue: Queue_Type ) return Boolean is Heap_Exhausted: Boolean := True; Dummy_Ptr: Item_Ptr_Type; procedure Delete is new Unchecked_Deallocation( Item_Type, Item_Ptr_Type ); begin begin Dummy_Ptr := new Item_Type; Delete( Dummy_Ptr ); -- restore the Item to the heap. exception when Storage_Error => Heap_Exhausted := True; end; return Heap_Exhausted; end; (this hasn't been compiled, so beware of small errors!) In general, I find that a function like "IsFull" is not very useful for allocating off of the heap. For one thing, it's quite inefficient to allocate-deallocate-reallocate for every addition to the Queue (assuming you're calling IsFull before each addition). It's more efficient and idiomatic to include an exception handler for the dreaded Storage_Error in the same code which would call IsFull. --bill