dynamic allocation of memory - help with error 
Author Message
 dynamic allocation of memory - help with error

checking NEW() to use all the available memory (64 k) i came accross this
weird error:

inside an infinite loop, the  first time i use NEW() to allocate 1020 Bytes,
the available memory "grows" rather than shrink (?) ... then it keeps
allocating the 1020 (and reducing the available memory) for 7 iterations and
available memory grows again ... and so on ... (program attached)

i'm using BP7 in windows mode. Heap size is 8192 bytes

any clues?

thanks

Jaime

program TestMem;
uses wincrt;
TYPE
  WastedArray = array [1..510] of integer;
var
  Node                                      :  ^WastedArray;
  InitialMem,MemUsed,RefMem  : longint;
begin
  InitialMem := MemAvail;
  writeln('Allocating ',SizeOf(WastedArray):6,' bytes (each time) from ',
  InitialMem:10);
  writeln('InitialMem  Memavail  MemUsed');

  REPEAT { infinite loop }
  begin
    RefMem := MemAvail;
    NEW(Node);
    MemUsed := RefMem-MemAvail;
    writeln(InitialMem:10,MemAvail:10,MemUsed:10);
    readln;
  end
  UNTIL (false);
end.



Wed, 18 Jun 1902 08:00:00 GMT  
 dynamic allocation of memory - help with error
it seems that the problem comes from using MemAvail to report on available
memory. I read it is not accurate.

so how do i know the size of heap allocated/free? (reliably!!!)



Wed, 18 Jun 1902 08:00:00 GMT  
 dynamic allocation of memory - help with error


Quote:
>it seems that the problem comes from using MemAvail to report on available
>memory. I read it is not accurate.

>so how do i know the size of heap allocated/free? (reliably!!!)

You don't. Instead install a heap error handler that returns nil when
the allocation cannot be satisfied.

Osmo



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

 Relevant Pages 

1. Dynamic memory allocation in interrupt code

2. Memory Allocation Errors (Simon Watkins)

3. dynamic array allocation?

4. Pointers and dynamic memory HELP

5. Memory-allocation just keeps growing out of control!

6. Real mode memory allocation and forced $0 offsets in BP7.0

7. Memory Allocation Sizes Directive and exec

8. BP7 DPMI memory allocation

9. Array access to large memory allocation

10. Array/Pointer memory allocation?

11. Memory allocation err, time measurment

12. memory allocation/comparison

 

 
Powered by phpBB® Forum Software