mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-10-25 19:01:34 +02:00
* fixed internal_memavail counting for tryresizemem
This commit is contained in:
parent
0fc3f2e559
commit
6bbb440811
@ -536,6 +536,7 @@ end;
|
|||||||
|
|
||||||
function SysTryResizeMem(var p:pointer;size : longint):boolean;
|
function SysTryResizeMem(var p:pointer;size : longint):boolean;
|
||||||
var
|
var
|
||||||
|
oldsize,
|
||||||
currsize,
|
currsize,
|
||||||
foundsize,
|
foundsize,
|
||||||
sizeleft,
|
sizeleft,
|
||||||
@ -550,6 +551,7 @@ begin
|
|||||||
{ fix p to point to the heaprecord }
|
{ fix p to point to the heaprecord }
|
||||||
pcurr:=pfreerecord(pointer(p)-sizeof(theaprecord));
|
pcurr:=pfreerecord(pointer(p)-sizeof(theaprecord));
|
||||||
currsize:=pcurr^.size and sizemask;
|
currsize:=pcurr^.size and sizemask;
|
||||||
|
oldsize:=currsize;
|
||||||
wasbeforeheapend:=(pcurr^.size and beforeheapendmask)<>0;
|
wasbeforeheapend:=(pcurr^.size and beforeheapendmask)<>0;
|
||||||
{ is the allocated block still correct? }
|
{ is the allocated block still correct? }
|
||||||
if currsize=size then
|
if currsize=size then
|
||||||
@ -655,6 +657,7 @@ begin
|
|||||||
pcurr^.size:=size or usedmask or (pcurr^.size and beforeheapendmask);
|
pcurr^.size:=size or usedmask or (pcurr^.size and beforeheapendmask);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
dec(internal_memavail,size-oldsize);
|
||||||
SysTryResizeMem:=true;
|
SysTryResizeMem:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -667,31 +670,29 @@ function SysReAllocMem(var p:pointer;size : longint):pointer;
|
|||||||
var
|
var
|
||||||
p2 : pointer;
|
p2 : pointer;
|
||||||
begin
|
begin
|
||||||
{ Free block? }
|
{ Free block? }
|
||||||
if size=0 then
|
if size=0 then
|
||||||
begin
|
begin
|
||||||
if p<>nil then
|
if p<>nil then
|
||||||
MemoryManager.FreeMem(p);
|
MemoryManager.FreeMem(p);
|
||||||
SysReallocmem:=P;
|
end
|
||||||
exit;
|
else
|
||||||
end;
|
{ Allocate a new block? }
|
||||||
{ Allocate a new block? }
|
if p=nil then
|
||||||
if p=nil then
|
begin
|
||||||
begin
|
p:=MemoryManager.GetMem(size);
|
||||||
p:=MemoryManager.GetMem(size);
|
end
|
||||||
SysReallocmem:=P;
|
else
|
||||||
exit;
|
{ Resize block }
|
||||||
end;
|
if not SysTryResizeMem(p,size) then
|
||||||
{ Resize block }
|
begin
|
||||||
if not SysTryResizeMem(p,size) then
|
p2:=MemoryManager.GetMem(size);
|
||||||
begin
|
if p2<>nil then
|
||||||
p2:= MemoryManager.GetMem(size);
|
Move(p^,p2^,size);
|
||||||
if p2<>nil then
|
MemoryManager.FreeMem(p);
|
||||||
Move(p^,p2^,size);
|
p:=p2;
|
||||||
MemoryManager.FreeMem(p);
|
end;
|
||||||
p:=p2;
|
SysReAllocMem:=p;
|
||||||
end;
|
|
||||||
SysReAllocMem := p;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -804,7 +805,10 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.32 2000-01-31 23:41:30 peter
|
Revision 1.33 2000-02-02 11:12:29 peter
|
||||||
|
* fixed internal_memavail counting for tryresizemem
|
||||||
|
|
||||||
|
Revision 1.32 2000/01/31 23:41:30 peter
|
||||||
* reallocmem fixed for freemem() call when size=0
|
* reallocmem fixed for freemem() call when size=0
|
||||||
|
|
||||||
Revision 1.31 2000/01/24 23:56:10 peter
|
Revision 1.31 2000/01/24 23:56:10 peter
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user