From: fpc-devel <fpc-devel-boun...@lists.freepascal.org> On Behalf Of Marcos 
Douglas B. Santos
Sent: Monday, 30 July 2018 22:25
To: FPC developers' list <fpc-devel@lists.freepascal.org>
Subject: Re: [fpc-devel] Why/how does the compiler have a non-trivial number 
ofmemory leaks after over two decades of development?

 

On Mon, Jul 30, 2018 at 9:14 AM, Sven Barth via fpc-devel 
<fpc-devel@lists.freepascal.org <mailto:fpc-devel@lists.freepascal.org> > wrote:

J. Gareth Moreton <gar...@moreton-family.com <mailto:gar...@moreton-family.com> 
> schrieb am Mo., 30. Juli 2018, 13:31:

I've noticed that the compiler doesn't use 
try...finally blocks to help with freeing 
blocks. I'm not sure why this is the case, 
but might be speed related.

 

Correct. Even implicit try-finally frame generation is disabled for the 
compiler source. 

 

Is performance more important than being correct?  :|

 

 

Freeing memory is irrelevant if your process is going to exit anyway right 
after freeing it. The OS doesn’t care about any memory your process has 
allocated at that time. All pages go back into the available pool.

 

Depending on how the allocation/free behaviour of the compiler looks like, but 
it might even make sense to use a memory manager that doesn’t even know how to 
free memory.

 

(I’m using windows terminology here, but I’m sure equivalent can be found on 
other platforms)

 

Reserve a large block of address space.

Install a vectored exception handler that reacts to an access violation that 
falls inside the reserved block by committing the memory between start and 
error address + 1MB (or more or less).

 

Naïvely and without error checking, Alloc gets reduced to:

 

var

  CurrentPtr: PByte;

 

function Alloc(Size: Integer):Pointer;

begin

  Size := (Size + 3) and not 3; //adjust depending on what allocation alignment 
is desired;

  If Size > 0 then begin

    Result := CurrentPtr;

    CurrentPtr := CurrentPtr + Size;

  end else

    Result := nil;

end;

 

procedure Free(p: Pointer); 

begin

  {do nothing}

end;

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to