[fpc-pascal] Re: Code conversion question - alloc and dealloc memory

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Oct 15 10:59:01 CEST 2009


On 15/10/2009, Graeme Geldenhuys <graemeg.lists at gmail.com> wrote:
>
>  ------------------------
>  function AllocateMemory( const Size: longint ): pointer;
>
>  procedure DeallocateMemory( Var P: pointer );

OK, I managed to convert those two functions to the following.. it now
compiles under my 64bit FPC.

-----------------------------
function AllocateMemory( const Size: ValUInt ): pointer;
begin
  GetMem( Result, size + sizeof( Size ) );
  PtrUInt(Result^) := Size;
  inc( Result, sizeof( Size ) );
end;

procedure DeallocateMemory( Var P: pointer );
var
  Size: ValUInt;
begin
  if P = nil then
    exit;

  dec( P, sizeof( size ) );
  Size := ValUInt(P^);
  FreeMem( P, Size + sizeof( Size ) );
  P := nil;
end;
-----------------------------

But based on Florian's reply, I assume I don't need to bother using
these methods, because FreeMem() will automatically know much much
memory to deallocate.


-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list