Jump to content

Wrong memoryused calculation


Tokay

Recommended Posts

  • 2 months later...
  • 1 month later...
  • 4 months later...

Hello Tokay,

I'm in last version: 1.90.0 build 1555 and "UniServerInstance.ServerResources.MemoryUsed" returns a value.

In my case this value is the exactly same that returns this function to caculate the memory used by a Delphi App (I get it from stackoverflow)

uses 
  FastMM4; //include this or method will return 0.
  
function GetMemoryUsed: UInt64;
var
  st: TMemoryManagerState;
  sb: TSmallBlockTypeState;
begin
  GetMemoryManagerState(st);
  result :=  st.TotalAllocatedMediumBlockSize +
           + st.TotalAllocatedLargeBlockSize;
  for sb in st.SmallBlockTypeStates do begin
    result := result + sb.UseableBlockSize * sb.AllocatedBlockCount;
  end;
end;

Note: My Delphi Version is 10.4.2

  • Like 1
Link to comment
Share on other sites

I've found what happend with memory calculation. When I added the FastMM4 module to the code, memory does not calculated. I could not found the reason couses of absent sources (UniGUIServer.pas).

I've used the FastMM4AVX from here:

https://github.com/maximmasiutin/FastMM4-AVX

It's commonly used free module.

Here is the test project, both issues (memory used and uptime) is present in it:

test16.7z

Please analyze and fix the issues! Thank you!

  • Upvote 1
Link to comment
Share on other sites

  • Administrators
program Project1;

uses
 FastMM4,
 uniWinUtils,
 Forms,
 ServerModule in 'ServerModule.pas' {UniServerModule: TUniGUIServerModule},
 MainModule in 'MainModule.pas' {UniMainModule: TUniGUIMainModule},
 Main in 'Main.pas' {MainForm: TUniForm},
 ServiceModule in 'ServiceModule.pas' {UniServiceModule: TUniGUIService},
 Unit37 in 'Unit37.pas';

{$R *.res}

function GetMemoryUsed: Int64;
var
  st: TMemoryManagerState;
  sb: TSmallBlockTypeState;
begin
  FastMM4.GetMemoryManagerState(st);
  result := st.TotalAllocatedMediumBlockSize + st.TotalAllocatedLargeBlockSize;
  for sb in st.SmallBlockTypeStates do
  begin
    result := result + Int64(sb.UseableBlockSize) * sb.AllocatedBlockCount;
  end;
end;

begin
  PGetMemoryUsedProc := GetMemoryUsed;
  Application.Initialize;
  TUniServerModule.Create(Application);
 Application.Run;
end.

Here is the solution. However, it will only work in next build!

 

  • Like 1
  • Upvote 1
Link to comment
Share on other sites

  • 1 month later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...