Board index » delphi » BP7: Heap overflow with Memavail>4MB

BP7: Heap overflow with Memavail>4MB

Hello Pascal experts, I have an interesting(?) problem:

At work we wrote a large simulation in BP7 as a protected mode target.
In one of the modules I allocate large amounts of memory in small
blocks(about 2k each). I do that by using arrays of pointers
where each pointer points to another array of numbers. Before allocating
each pointer (using getmem) I check for enough memory by using the Memavail
function. Despite all that, I got a run time error of "heap overflow"
when memavail shows plenty of memory(more than 4MB). So my questions are:

1. Is there a limit on the number of memory blocks I can allocate in
   BP7 , protected mode target?

2. If there is, Is there a way to increase the number of blocks I can
   allocate? Is this got something to do with the DPMI server?

Please post a reply here or send mail to l...@actcom.co.il.

Thanks in advance,
Lior

 

Re:BP7: Heap overflow with Memavail>4MB


Quote
In article <DAuEz8....@actcom.co.il> l...@actcom.co.il (Lior David) writes:
>1. Is there a limit on the number of memory blocks I can allocate in
>   BP7 , protected mode target?

Yes, there's a very restrictive limit.  I don't think it is documented
anywhere, but in my experience there's a limit of a few thousand allocations.

Quote
>2. If there is, Is there a way to increase the number of blocks I can
>   allocate? Is this got something to do with the DPMI server?

You can't increase the number of blocks, but you can do suballocations within
blocks.  This is described in the manual in the section on the HeapXXXX
variables.

Duncan Murdoch

Re:BP7: Heap overflow with Memavail>4MB


l...@actcom.co.il (Lior David):

Quote
> each pointer (using getmem) I check for enough memory by using the Memavail
> function. Despite all that, I got a run time error of "heap overflow"
> when memavail shows plenty of memory(more than 4MB). So my questions are:

It could be that your heap has become very fragmented. You should
check with Maxavail instead of Memavail. Memavail reports the amount
of free memory on the heap, Maxavail reports the largest block of
memory you can allocate.

(I'm writing this from memory, but it should be right.)

/Jonas
_______________________
Jonas Eckerman     IIS
j...@algonet.se    FSDB

Re:BP7: Heap overflow with Memavail>4MB


# article..: "BP7: Heap overflow with Memavail>4MB"
# from.....: l...@actcom.co.il
# date.....: 27.06.95

l> 1. Is there a limit on the number of memory blocks I can allocate in
l>    BP7 , protected mode target?

Yes, there is.
l>
l> 2. If there is, Is there a way to increase the number of blocks I can
l>    allocate? Is this got something to do with the DPMI server?

BP uses 'little' and 'huge' mem-blocks inside the heap. The number of
huge mem-blocks is limited, because the intel-processors can only handle a
limited number of GDT's - the table of descriptors.

'Little' mem-blocks were put together in huge blocks, so you can use as  
much little blocks you want.

There are two variables declared by BP: HEAPBLOCK and HEAPLIMIT.
Please read the online-help or the documentation for more details.

To solve your problem, just change the values before allocating any  
memory.

Good luck,

    _        ___
   (_       _ |  _   _       Location at:
    _) (_) (  | (_| (_)      d.mankow...@ldb.han.de
## CrossPoint v3.02 ##

Re:BP7: Heap overflow with Memavail>4MB


Quote
In article <DAuEz8....@actcom.co.il>, l...@actcom.co.il (Lior David) writes:
> Hello Pascal experts, I have an interesting(?) problem:

> At work we wrote a large simulation in BP7 as a protected mode target.
> In one of the modules I allocate large amounts of memory in small
> blocks(about 2k each). I do that by using arrays of pointers
> where each pointer points to another array of numbers. Before allocating
> each pointer (using getmem) I check for enough memory by using the Memavail
> function. Despite all that, I got a run time error of "heap overflow"
> when memavail shows plenty of memory(more than 4MB). So my questions are:

  I seem to recall that in protected mode the number returned by MemAvail has
  very little to do with the amount of memory actually available. When
  debugging programs I sometimes make them display MemAvail in some corner of
  the screen, and when I did this in protected mode with one program (the
  only time I've tried it in PM) I was told that I had 80 Mb left. I found this
  a little surprising as I had only 2 Mb memory to begin with.
  I also seem to recall that other people have complained about this. Does
  anyone know anything for certain about this?
  And BTW, there are some BIOS/DOS calls that return the same as MemAvail. Can
  these be used instead or is MemAvail just a call to these?

  --Lars M.

Re:BP7: Heap overflow with Memavail>4MB


In article <3tit2t$...@skirfir.ifi.uio.no>, lar...@ifi.uio.no says...

Quote

>In article <DAuEz8....@actcom.co.il>, l...@actcom.co.il (Lior David) writes:

>  I seem to recall that in protected mode the number returned by MemAvail has
>  very little to do with the amount of memory actually available. When
>  debugging programs I sometimes make them display MemAvail in some corner of
>  the screen, and when I did this in protected mode with one program (the
>  only time I've tried it in PM) I was told that I had 80 Mb left. I found
this
>  a little surprising as I had only 2 Mb memory to begin with.
>  I also seem to recall that other people have complained about this. Does
>  anyone know anything for certain about this?
>  And BTW, there are some BIOS/DOS calls that return the same as MemAvail. Can
>  these be used instead or is MemAvail just a call to these?

>  --Lars M.

        The reason you are getting 80mb of free memory is that your DMPI server
is returning the total amount of memory that can be allocated, this includes
the virtual memory that the DMPI server will provide from disk space. So
basically, in protected mode it doesn't matter how much physical memory you
have since the DPMI server will just demand load selectors on an as needed
basis.  So basically, you are right, MemAvail doesn't return the amount of
physical memory available, but instead the amount of "simulated" memory
available. You really shouldn't have a need to determine the amount of physical
memory, but if you have to you will need to look into the DPMI API to get that
information.

                                                        William Brooks

Re:BP7: Heap overflow with Memavail>4MB


Quote
In article <DAuEz8....@actcom.co.il>, l...@actcom.co.il (Lior David) writes:
> Hello Pascal experts, I have an interesting(?) problem:

> At work we wrote a large simulation in BP7 as a protected mode target.
> In one of the modules I allocate large amounts of memory in small
> blocks(about 2k each). I do that by using arrays of pointers
> where each pointer points to another array of numbers. Before allocating
> each pointer (using getmem) I check for enough memory by using the Memavail
> function. Despite all that, I got a run time error of "heap overflow"
> when memavail shows plenty of memory(more than 4MB). So my questions are:

Storage allocation in protected mode has two constraints:

   1. available memory
   2. available segment descriptors.

You can run out of descriptors before you run out of memory. See
the manual for a full explanation of this and how to avoid
problems with certain memory allocation patterns. In my manual
it is on pages 268-269 under the title of the DOS protected mode
heap manager in the language definition. They are also covered
in the alphabetic run-time library material.

The key is two variables: heaplimit and heapblock. The run-time
library material on getmem does not cross-reference these
variables.

Too bad functions and variables that deal with memory
allocation do not all begin with the same few characters, so
that they would appear near each other in the reference.

Brent
--
Brent Beach, Victoria, BC

Other Threads