Heap error while allocating dynamic array in protected. 
Author Message
 Heap error while allocating dynamic array in protected.

I tried to allocate screen arrays for my SVGA library, which use virtual
scrooling in >15bpp . In every case it finished x=1500 and y=1500 (nearly),
but I have above 64megs free. I need sombody, who will help me with this
problem. It's possible that I forgot some basic command, or etc.. (we're
just humans :)).

I include example program:

{testing allocation program, I wrote it from scratch so I hope it'll work,
but u must keep y<=1500}

uses dos;

type
            PscanLine = ^Tscanline;
            TscanLine = array [0..16000] of longint; {keep 64 kb}

            PScreen    =    ^TScreen;
            TScreen    = record
                                     DATA : array [0..16000] of PScanline;
{y axis of screen, each store pointer 2 x array}
                                   {...}
                                   end;

var
      s : PScreen;
      j : word;

{$IFNDEF DPMI} Just for protect {$ENDIF}

begin
  Getmem(S, sizeof(S^)); {allocation of y arrays, can be adjusted for
optimized height of bytes}

    X:=1500; Y:=1500; {add more& it'll crash down program with 203 error}

 for j:=0 to y do
   getmem(S^.DATA[j], y shl 2); {allocate each scanline (shl 2 because of
longint)}

{now do something....}

{for j:=y downto 0 do
     freemem(S^.DATA[j], y shl 2);  {de-alloc all scanlines}

freemem(S,  sizeof(S^)); {de-alloc main screen}

end.



Wed, 18 Jun 1902 08:00:00 GMT  
 Heap error while allocating dynamic array in protected.

Quote:

>I tried to allocate screen arrays for my SVGA library, which use virtual
>scrooling in >15bpp . In every case it finished x=1500 and y=1500 (nearly),
>but I have above 64megs free. I need sombody, who will help me with this
>problem. It's possible that I forgot some basic command, or etc.. (we're
>just humans :)).

>I include example program:

>{testing allocation program, I wrote it from scratch so I hope it'll work,
>but u must keep y<=1500}

>uses dos;

>type
>            PscanLine = ^Tscanline;
>            TscanLine = array [0..16000] of longint; {keep 64 kb}

>            PScreen    =    ^TScreen;
>            TScreen    = record
>                                     DATA : array [0..16000] of PScanline;
>{y axis of screen, each store pointer 2 x array}
>                                   {...}
>                                   end;

>var
>      s : PScreen;
>      j : word;

>{$IFNDEF DPMI} Just for protect {$ENDIF}

>begin
>  Getmem(S, sizeof(S^)); {allocation of y arrays, can be adjusted for
>optimized height of bytes}

Haven't you heard of New()?

Quote:

>    X:=1500; Y:=1500; {add more& it'll crash down program with 203 error}

> for j:=0 to y do
>   getmem(S^.DATA[j], y shl 2); {allocate each scanline (shl 2 because of
>longint)}

This has been handled just before. You should really read the old
messages. You allocate 3000 bytes, therefore with default settings BP
will allocate a new selector for each allocation. You can fix this by
modifying the heapblock and heaplimit:

for example:

heapblock:=63*1024
HeapLimit:=20480;

With these you can fit 21 allocations of 3000 bytes in a segment. Set
those at the very beginning of the program. HeapLimit tells when to
allocate a new segment for each allocation and heapblock tells the size
of the block used for small allocations.

Quote:
>{now do something....}

>{for j:=y downto 0 do
>     freemem(S^.DATA[j], y shl 2);  {de-alloc all scanlines}

>freemem(S,  sizeof(S^)); {de-alloc main screen}

Dispose(S);

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. dynamic allocate the size of an array ?

2. Allocating memory under protected mode (BP7)

3. Q:Allocating memory in protected mode.

4. Dinamic arrays of objects (how to allocate and handle)

5. DELPHI:How to allocate array of objects dynamically at runtime

6. Unexpected heap overflow in protected mode program compiled by BP7

7. Heap Overflow Error - runtime error 203

8. Source Code for Error 203 Heap Overflow error (Urgent Help needed)

9. Dynamic code in protected mode (FPC)

10. Dynamic code in protected mode (FPC)

11. dynamic array

12. Dynamic array in database

 

 
Powered by phpBB® Forum Software