Board index » delphi » getting access to all 16M of heap memory in BP7

getting access to all 16M of heap memory in BP7

I have a maze program that I wrote for my nephew. It keeps him busy but
now he'd like to try solving a few BIG mazes. Storing the maze in the heap
of BP7 should let me make one of roughly 4000x4000 cells which should keep
him happy.

The problem is that the program takes it's size from the command line.
Here's the snippet of code:

const
  MaximumMazeRows = 16000;
  MaximumMazeCols = 16000;

type
  MazeCellType   = (Wall, Path, Trail, Notrail);
  MazeCellSet    = set of MazeCellType;

  DirectionType  = (North, South, West, East);
  DirectionSet   = set of DirectionType;

  MazeRowType    = array [1 .. MaximumMazeRows] of byte;
  MazeRowPointer = ^MazeRowType;

  MazeColumnType = array [1 .. MaximumMazeCols] of MazeRowPointer;
  MazePointer    = ^MazeColumnType;

  function CreateMazeStorage(rows, cols : integer) : MazePointer;

  var
    themaze : MazePointer;
    row,
    col     : integer;
    bytes   : word;

  begin
    if maxavail < sizeof(themaze^) then
      begin
        writeln('Couldn''t allocate memory for the column array.');
        halt(1);
      end;

    new(themaze);

    { figure out how many bytes to allocate for each row. We round it up to
      the nearest four bytes just to make sure }

    bytes := 4 * (cols div 4 + 1);

    { allocate that much space for each row }

    for row := 1 to rows do
      begin
        if maxavail < bytes then
          begin
            writeln('Couldn''t allocate memory for row ', row, ' of ', rows);
            halt(1);
          end;

        GetMem(themaze^[row], bytes);
      end;

    CreateMazeStorage := themaze;
  end;

the idea is that a maze is a pointer to an array of 16000 row pointers.
Each of those row pointers will then point to an array of 16000 bytes.
Obviously I can't allocate that much space so I use getmem to allocate as
much space as I really need instead of all 16000.

With the above I should easily be able to make an array of 3000x3000
cells. That's only about 9MBytes which is smaller than the 16MByte I'm
allowed on the heap in BP7. The problem is it dies at about 8MBytes. I
can't seem to allocate space for a maze bigger than 2100x2100 or so.
--
john R. Latala
jrlat...@golden.net

 

Re:getting access to all 16M of heap memory in BP7


<jrlat...@shell.golden.net> schreef in bericht
news:9v2bhr$4qc$1@shell.golden.net...

Quote
> I have a maze program that I wrote for my nephew. It keeps him busy but
> now he'd like to try solving a few BIG mazes. Storing the maze in the
heap
> of BP7 should let me make one of roughly 4000x4000 cells which should
keep
> him happy.

> The problem is that the program takes it's size from the command line.
> Here's the snippet of code:

> const
>   MaximumMazeRows = 16000;
>   MaximumMazeCols = 16000;

> type
>   MazeCellType   = (Wall, Path, Trail, Notrail);
>   MazeCellSet    = set of MazeCellType;

>   DirectionType  = (North, South, West, East);
>   DirectionSet   = set of DirectionType;

>   MazeRowType    = array [1 .. MaximumMazeRows] of byte;
>   MazeRowPointer = ^MazeRowType;

>   MazeColumnType = array [1 .. MaximumMazeCols] of MazeRowPointer;
>   MazePointer    = ^MazeColumnType;

>   function CreateMazeStorage(rows, cols : integer) : MazePointer;

>   var
>     themaze : MazePointer;
>     row,
>     col     : integer;
>     bytes   : word;

>   begin
>     if maxavail < sizeof(themaze^) then
>       begin
>         writeln('Couldn''t allocate memory for the column array.');
>         halt(1);
>       end;

>     new(themaze);

>     { figure out how many bytes to allocate for each row. We round it
up to
>       the nearest four bytes just to make sure }

>     bytes := 4 * (cols div 4 + 1);

>     { allocate that much space for each row }

>     for row := 1 to rows do
>       begin
>         if maxavail < bytes then
>           begin
>             writeln('Couldn''t allocate memory for row ', row, ' of ',
rows);
>             halt(1);
>           end;

>         GetMem(themaze^[row], bytes);
>       end;

>     CreateMazeStorage := themaze;
>   end;

> the idea is that a maze is a pointer to an array of 16000 row pointers.
> Each of those row pointers will then point to an array of 16000 bytes.
> Obviously I can't allocate that much space so I use getmem to allocate
as
> much space as I really need instead of all 16000.

> With the above I should easily be able to make an array of 3000x3000
> cells. That's only about 9MBytes which is smaller than the 16MByte I'm
> allowed on the heap in BP7. The problem is it dies at about 8MBytes. I
> can't seem to allocate space for a maze bigger than 2100x2100 or so.
> --
> john R. Latala
> jrlat...@golden.net

The maximum heap in BP is 64 MB and not 16, so you can make your nephew a
lot happier than you thought.
I think the problem is in Windows. Rightclick the BP.EXE program, or the
shortcut that is used to start BP, choose the Properties / Memory , set
all the fields to AUTO, press OK. That's it.

Femme

Re:getting access to all 16M of heap memory in BP7


In article <u19i1kb48cm...@corp.supernews.com>,

Quote
Femme Verbeek <f...@{*word*104}jet.nl> wrote:
><jrlat...@shell.golden.net> schreef in bericht
>news:9v2bhr$4qc$1@shell.golden.net...
>> I have a maze program that I wrote for my nephew. It keeps him busy but
>> now he'd like to try solving a few BIG mazes. Storing the maze in the
>heap
>> of BP7 should let me make one of roughly 4000x4000 cells which should
>keep
>> him happy.

>> The problem is that the program takes it's size from the command line.
>> Here's the snippet of code:

... code snipped ...

Quote
>> With the above I should easily be able to make an array of 3000x3000
>> cells. That's only about 9MBytes which is smaller than the 16MByte I'm
>> allowed on the heap in BP7. The problem is it dies at about 8MBytes. I
>> can't seem to allocate space for a maze bigger than 2100x2100 or so.

>The maximum heap in BP is 64 MB and not 16, so you can make your nephew a
>lot happier than you thought.

On my system MemAvail shows that but I've never been able to get access to
all of it. I wrote a short test program that just kept allocating a 4Kbyte
array as often as it could. With MaxAvail and MemAvail both returning
numbers like 40MBytes free it crashed with an out of heap memory error.

Quote
>I think the problem is in Windows. Rightclick the BP.EXE program, or the
>shortcut that is used to start BP, choose the Properties / Memory , set
>all the fields to AUTO, press OK. That's it.

Been there, done that, doesn't help.

--
john R. Latala
jrlat...@golden.net

Re:getting access to all 16M of heap memory in BP7


JRS:  In article <9v2bhr$4q...@shell.golden.net>, seen in
news:comp.lang.pascal.borland, jrlat...@shell.golden.net wrote at Mon,
10 Dec 2001 07:58:35 :-

Quote

>With the above I should easily be able to make an array of 3000x3000
>cells. That's only about 9MBytes which is smaller than the 16MByte I'm
>allowed on the heap in BP7. The problem is it dies at about 8MBytes. I
>can't seem to allocate space for a maze bigger than 2100x2100 or so.

Possibly 2048*???? maybe?

You could be running out of space for heap allocation pointers, or
something line that.  There is a section in the printed manual.

You could either persuade the lad that a maze of 2000*8000 is as good as
one of 4000*4000, or use, say, 1000 allocated chunks each representing a
4*4000 slice.

For a start, ignore the desired structure and see how much memory, in
what size pieces, you can physically grab; you can then decide on a
sufficiently convenient strategy.

I'm assuming you are running under DOS, or equivalent; compiling for
Windows mode may differ.

You may be able to get Delphi off a magazine cover; much BP7 code can be
adapted for Delphi console mode without great difficulty, and this gives
32-bit ops & more capacity.

For example, I write my Web-site-local-links-checker in BP7, but when my
site got too big I found I needed the Delphi version, compiling in a DOS
box with   DCC32 -cc cheklinx   or something like that.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.

Re:getting access to all 16M of heap memory in BP7


Quote
<jrlat...@shell.golden.net> wrote in message

news:9v2bhr$4qc$1@shell.golden.net...

[..]

Quote
> With the above I should easily be able to make an array of 3000x3000
> cells. That's only about 9MBytes which is smaller than the 16MByte I'm
> allowed on the heap in BP7.

BP7 allows you up to 64MB, NOT 16MB. 16MB is a 80286 limit, not a 16-bit
protected mode limit.

Quote
> The problem is it dies at about 8MBytes. I
> can't seem to allocate space for a maze bigger than 2100x2100 or so.

Put this right at the start of your program:

     HeapLimit := 1024 * 16;
     HeapBlock := 1024 * 60;

--
Jay

Jason Burgon - Author of "Graphic Vision"  GUI for DOS/DPMI
=== Free LFN capable Dos/WinDos replacement and ===
=== New Graphic Vision  version 2.21 available from:  ===
http://www.jayman.demon.co.uk

Re:getting access to all 16M of heap memory in BP7


Quote

> On my system MemAvail shows that but I've never been able to get access
to
> all of it. I wrote a short test program that just kept allocating a
4Kbyte
> array as often as it could. With MaxAvail and MemAvail both returning
> numbers like 40MBytes free it crashed with an out of heap memory error.

> >I think the problem is in Windows. Rightclick the BP.EXE program, or
the
> >shortcut that is used to start BP, choose the Properties / Memory ,
set
> >all the fields to AUTO, press OK. That's it.

> Been there, done that, doesn't help.

I see what you mean now.
Previously there was a discussion in this group called More memory. (The
solution was given there.)
When testing with Win ME on a machine with 384MB memory, I got 64 MB in
BP and was able to use it.
I tested your method now on a machine with 32 MB and win 98. Memavail
reports 30 MB but when using 4000 byte blocks you get an arror after
allocating 8 MB.

This worked for me, start your program with

Heaplimit:=1024*8
Heapblock:=6144*8

Note:  Windows in DOS mode does not report the correct available amount
of memory to memavail or maxavail. So checking them does not guarantee
that you can assign your block. This is probab+y only important if you
approach the 64 MB.

Note2:
If you check Maxavail before each assigning, windows may grant you swap
memory if there is less than the assigned memory in hardware available.
This way I can get 64 MB on a 32MB machine.
Not checking maxavail, or checking Memavail instead before calling getmem
gives me just 30 MB on a 32 MB machine

Greetings Femme

Re:getting access to all 16M of heap memory in BP7


Quote
In article <JPaO$QJWtUF8E...@merlyn.demon.co.uk>, Dr John Stockton wrote:
> JRS:  In article <9v2bhr$4q...@shell.golden.net>, seen in

> I'm assuming you are running under DOS, or equivalent; compiling for
> Windows mode may differ.

> You may be able to get Delphi off a magazine cover; much BP7 code can be
> adapted for Delphi console mode without great difficulty, and this gives
> 32-bit ops & more capacity.

> For example, I write my Web-site-local-links-checker in BP7, but when my
> site got too big I found I needed the Delphi version, compiling in a DOS
> box with   DCC32 -cc cheklinx   or something like that.

One can also use Free Pascal, specially if Graph was used, that could be
handy.

Re:getting access to all 16M of heap memory in BP7


In article <1008037601.10487.1.nnrp-10.9e98b...@news.demon.co.uk>,

Quote
Jason Burgon <ja...@jayman.demon.co.uk> wrote:
><jrlat...@shell.golden.net> wrote in message
>news:9v2bhr$4qc$1@shell.golden.net...

>[..]

>> With the above I should easily be able to make an array of 3000x3000
>> cells. That's only about 9MBytes which is smaller than the 16MByte I'm
>> allowed on the heap in BP7.

>BP7 allows you up to 64MB, NOT 16MB. 16MB is a 80286 limit, not a 16-bit
>protected mode limit.

>> The problem is it dies at about 8MBytes. I
>> can't seem to allocate space for a maze bigger than 2100x2100 or so.

>Put this right at the start of your program:

>     HeapLimit := 1024 * 16;
>     HeapBlock := 1024 * 60;

That did the trick. I added that to my linked list test program and it
happily linked 4KByte blocks until it filled 64MBytes of memory. It
outputs a running total of how much space it thinks it's used and how much
is left by subtracting MaxAvail from it's initial value. It runs along
pretty good until it gets to within a few megabytes of filling the heap.
That's when the disk light comes on for a few minutes! :-)

I made the changes to my maze program and made a maze of 4001x4001 cells.
It's a mean program because you can't see the whole maze and if you take a
deadend you have to visit every cell in that area before it'll let you
out! Probably won't see him for a few days ... if not longer.

I'm not sure what's really going on though because if you don't put those
two lines in you only get access to about 8MByte. Put those two lines in
and you get all 64MByte. Setting either of those values must do some
internal magic somewhere otherwise I'd expect you to get all the memory
anyway.
--
john R. Latala
jrlat...@golden.net

Re:getting access to all 16M of heap memory in BP7


It's easily explained:

BP has only 2000 selektors available, this would mean it only could
allocate 2000 segments (in protected mode) and you only had let's say
2000 dynamic memory areas.

But BP 7 does some trick: it allocates larger blocks than you requested
and suballocated your memory requests from them. For suballocation it
doesn't need selectors, because it is manages internally and not by CPU.
With these changed values only the size of the larger allocated blocks
is changes and how big your memory request must be that BP allocates a
own selector for it (doesen't use suballocation for it).

Greetings

Markus

Re:getting access to all 16M of heap memory in BP7


Quote
<jrlat...@shell.golden.net> wrote in message

news:9v7em5$bme$1@shell.golden.net...

Quote
> I'm not sure what's really going on though because if you don't put those
> two lines in you only get access to about 8MByte. Put those two lines in
> and you get all 64MByte. Setting either of those values must do some
> internal magic somewhere otherwise I'd expect you to get all the memory
> anyway.

HeapBlock and HeapLimit are documented in the IDE help. A BP7 program only has
about 2000 selectors to play with, so if you run out of selectors, the program
cannot allocate any more memory. Setting a higher value for HeapBlock means
each selector is mapped to bigger chunk of memory (60K instead of the default
8K. 8K x 2000 = 15.6MB, 60K * 2000 = 117MB.

HeapLimit defines the size above which an individual memory request will get
its own selector (regardless of the HeapBlock). The default value is only 1K,
so all memory requests >= 1k will consume a precious selector.

Note: Borland warn to keep HeapLimt * 4 <= HeapBlock.

Re:getting access to all 16M of heap memory in BP7


In article <1008269254.23380.0.nnrp-13.9e98b...@news.demon.co.uk>,

Quote
Jason Burgon <ja...@jayman.demon.co.uk> wrote:
><jrlat...@shell.golden.net> wrote in message
>news:9v7em5$bme$1@shell.golden.net...

>> I'm not sure what's really going on though because if you don't put those
>> two lines in you only get access to about 8MByte. Put those two lines in
>> and you get all 64MByte. Setting either of those values must do some
>> internal magic somewhere otherwise I'd expect you to get all the memory
>> anyway.

>HeapBlock and HeapLimit are documented in the IDE help. A BP7 program only has
>about 2000 selectors to play with, so if you run out of selectors, the program
>cannot allocate any more memory. Setting a higher value for HeapBlock means
>each selector is mapped to bigger chunk of memory (60K instead of the default
>8K. 8K x 2000 = 15.6MB, 60K * 2000 = 117MB.

>HeapLimit defines the size above which an individual memory request will get
>its own selector (regardless of the HeapBlock). The default value is only 1K,
>so all memory requests >= 1k will consume a precious selector.

The limited selector availability is the part I didn't know. Thanks to
everybody who offered help/suggestions.

P.S. nephew's still working on that first maze! His mum says it sure is
     is quiet at their place. :-)
--
john R. Latala
jrlat...@golden.net

Other Threads