Recent

Author Topic: Doubt with freemem and freememsize  (Read 1970 times)

damieiro

  • Full Member
  • ***
  • Posts: 200
Doubt with freemem and freememsize
« on: September 24, 2018, 03:07:21 pm »
Actually i see two kinds of freemem in memory manager;
Code: Pascal  [Select][+][-]
  1. TMemoryManager = record
  2.     NeedLock            : boolean;   // Obsolete
  3.     Getmem              : Function(Size:ptruint):Pointer;
  4.     Freemem             : Function(p:pointer):ptruint;
  5.     FreememSize         : Function(p:pointer;Size:ptruint):ptruint;  {WHEN IS USED?}
  6.     AllocMem            : Function(Size:ptruint):Pointer;
  7.     ReAllocMem          : Function(var p:pointer;Size:ptruint):Pointer;
  8.     MemSize             : function(p:pointer):ptruint;
  9.     InitThread          : procedure;
  10.     DoneThread          : procedure;
  11.     RelocateHeap        : procedure;
  12.     GetHeapStatus       : function :THeapStatus;
  13.     GetFPCHeapStatus    : function :TFPCHeapStatus;
  14.   end;            
  15.  

    Freemem             : Function(p:pointer):ptruint;
    FreememSize       : Function(p:pointer;Size:ptruint):ptruint;

I do not see implementation differences. It seems that FreeMemSize calls freemen discarding size parameter
When is used FreememSize in free pascal? What are it's use intended for?  (freeing the last size bytes?)

On the other hand, the freemem uses -> https://www.freepascal.org/docs-html/rtl/system/freemem.html


Code: Pascal  [Select][+][-]
  1. procedure Freemem(  p: pointer;  Size: PtrUInt);
  2.  
  3. function Freemem(  p: pointer):PtrUInt;

Does matter to the procedural freemen the value of size?.  It seems it's ignored and do a freemem...
« Last Edit: September 24, 2018, 04:14:53 pm by damieiro »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Doubt with freemem and freememsize
« Reply #1 on: September 24, 2018, 03:24:02 pm »
Turbo Pascal used freememsize. IOW the heapmanager did not store size, you had to provide it yourself on free.

Delphi stores the size in every block, so you don't need to pass size to freemem.

I assume the difference is kept in the memorymanager, to allow a purely TP clone (e.g. 16-bit) to save some memory on every allocation.

damieiro

  • Full Member
  • ***
  • Posts: 200
Re: Doubt with freemem and freememsize
« Reply #2 on: September 24, 2018, 04:20:35 pm »
Ok. It makes sense.
I used allways FPC mode. And doesn't go for my oldie TP.

So Procedural call in FPC is treated like freemen (well, it calls to the manager for the entry freegetmemsize... but size seems ignored).

I was only guessing if a freemem with size were a kind of realloc lowering the memory...

 

TinyPortal © 2005-2018