comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <Nick.Roberts@dial.pipex.com>
Subject: Re: Dynamic Allocation problem
Date: 1997/04/05
Date: 1997-04-05T00:00:00+00:00	[thread overview]
Message-ID: <01bc41d5$caf49f80$c2fa82c1@xhv46.dial.pipex.com> (raw)
In-Reply-To: 5i436p$248c@newssvr01-int.news.prodigy.com




Matthew Givens <NKSW39B@prodigy.com> wrote in article
<5i436p$248c@newssvr01-int.news.prodigy.com>...
> Okay, I'm working on an Ada program that uses a LOT of dynamic
allocation.
> 
> 
> The program is supposed to retrieve records from an ORACLE database and 
> load them into a Listbox (I'm running on a Sun).  It works fine for about

> 1600 records, then croaks on an attempt to dynamically allocate the new 
> memory.
> 
> The listbox data is stored (don't blame me, I didn't design it) in one 
> large string, each row separated by LF's.  Only 100 rows at a time are 
> actually displayed, but all rows are stored in the string.  Now, at the 
> time of the crash, the listbox string takes up approx 300K, with the new 
> row taking up 230 bytes.  When I try to allocate the new memory (using 
> new), it dies with a STORAGE_ERROR exception.
> 
> Now, is there any way for me to check the amount of available storage 
> BEFORE I actually try the allocation?  It would be helpful to me in 
> debugging if I could tell how close to the memory limit I am at any given

> point, but I don't know how to do this.  Any help is appreciated.

One way is simply to use an exception handler to catch the Storage_Error
exception, and then take appropriate action.

Perhaps, in your case, if the exception happens, all you need to do is
display a message (in a dialog) to the user to the effect that not all the
data could be presented in one go, then display the list data which could
be loaded, and provide an option (perhaps an extra button) to allow the
remaining data to be loaded and presented. Of course, your application may
not be as simple as that.

You may want to put the loader code into a separate procedure, which
returns a flag indicating whether all the data was loaded or not. The
procedure would initialise the flag to 'all data loaded', but the exception
handler would set it to 'not all loaded'.

Nick.





      parent reply	other threads:[~1997-04-05  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-04  0:00 Dynamic Allocation problem Matthew Givens
1997-04-05  0:00 ` Robert A Duff
1997-04-05  0:00 ` Nick Roberts [this message]
replies disabled

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