comp.lang.ada
 help / color / mirror / Atom feed
* Dynamic Allocation problem
@ 1997-04-04  0:00 Matthew Givens
  1997-04-05  0:00 ` Nick Roberts
  1997-04-05  0:00 ` Robert A Duff
  0 siblings, 2 replies; 3+ messages in thread
From: Matthew Givens @ 1997-04-04  0:00 UTC (permalink / raw)



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.

-
"Outside of a dog, a book is a Man's best friend.  Inside of a dog it's 
very dark." << Iceman >>





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Dynamic Allocation problem
  1997-04-04  0:00 Dynamic Allocation problem Matthew Givens
  1997-04-05  0:00 ` Nick Roberts
@ 1997-04-05  0:00 ` Robert A Duff
  1 sibling, 0 replies; 3+ messages in thread
From: Robert A Duff @ 1997-04-05  0:00 UTC (permalink / raw)



In article <5i436p$248c@newssvr01-int.news.prodigy.com>,
Matthew Givens <NKSW39B@prodigy.com> wrote:
>Now, is there any way for me to check the amount of available storage 
>BEFORE I actually try the allocation?

You could write your own storage pool, using whatever allocation
algorithm you like, and this pool type could have a function that
returns the amount of free space (or the largest contiguous chunk of
free space, or whatever else you find useful).  You would then put "for
My_Access_Type'Storage_Pool use ...;".

- Bob




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Dynamic Allocation problem
  1997-04-04  0:00 Dynamic Allocation problem Matthew Givens
@ 1997-04-05  0:00 ` Nick Roberts
  1997-04-05  0:00 ` Robert A Duff
  1 sibling, 0 replies; 3+ messages in thread
From: Nick Roberts @ 1997-04-05  0:00 UTC (permalink / raw)





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.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-04-05  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-04-04  0:00 Dynamic Allocation problem Matthew Givens
1997-04-05  0:00 ` Nick Roberts
1997-04-05  0:00 ` Robert A Duff

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