Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » memory consumption of my application
Re: memory consumption of my application [message #59859 is a reply to message #59856] Sat, 06 May 2023 22:34 Go to previous messageGo to previous message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi,

I found these 2 codes for windows and linux. I think they are reasonable to have a base. On windows I did the test and the values don't match with the manager since they use different structure (as the note in the example). On linux the values are already close to the test application!


windows:

void defP(){
	    // Task Manager windows 10 uses VM_COUNTERS_EX2 similar structure is defined (in ntddk.h)
		MEMORYSTATUSEX memInfo;
		memInfo.dwLength = sizeof(MEMORYSTATUSEX);
		GlobalMemoryStatusEx(&memInfo);
		DWORDLONG totalVirtualMem = memInfo.ullTotalPageFile;
		
		DWORDLONG virtualMemUsed = memInfo.ullTotalPageFile - memInfo.ullAvailPageFile;
		
		PROCESS_MEMORY_COUNTERS_EX pmc;
		GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc));
		SIZE_T virtualMemUsedByMe = pmc.PrivateUsage;
		
		DWORDLONG totalPhysMem = memInfo.ullTotalPhys;
		
		DWORDLONG physMemUsed = memInfo.ullTotalPhys - memInfo.ullAvailPhys;
		
		SIZE_T physMemUsedByMe = pmc.WorkingSetSize;
		
		SIZE_T  x=pmc.PagefileUsage;
		SIZE_T y=pmc.PrivateUsage;
		Cout() <<"m virtual usada-----> " << virtualMemUsedByMe/1024 << EOL;
		Cout() <<"m fisica usada-----> " << physMemUsed/1024/1024 << EOL;
		Cout() <<"total m  usada-----> " << totalPhysMem << EOL;
		Cout() <<"m privada usada-----> " << y/1024 << EOL;
			
}
 
CONSOLE_APP_MAIN
{
  SetLanguage("pt-br");
  SetDateFormat("%3:02d/%2:02d/%1:4d"); // format code in editor
  SetDateScan("dmy");
  
  defP();
  
}
 
linux:
#include <iostream>
#include <Core/Core.h>
#include <SysInfo/SysInfo.h>
 
using namespace Upp;
 
int parseLine(char* line){
    // This assumes that a digit will be found and the line ends in " Kb".
    int i = strlen(line);
    const char* p = line;
    while (*p <'0' || *p > '9') p++;
    line[i-3] = '\0';
    i = atoi(p);
    return i;
}
 
int getValue(){ //Note: this value is in KB!
    FILE* file = fopen("/proc/self/status", "r");
    int result = -1;
    char line[128];
 
    while (fgets(line, 128, file) != NULL){
        if (strncmp(line, "VmRSS:", 6) == 0){
            result = parseLine(line);
            break;
        }
    }
    fclose(file);
    return result;
}
 
CONSOLE_APP_MAIN 
{
	Cout() << "--> " << getValue() << EOL;
}
 
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: StrInt returning value
Next Topic: U++ Allocator causing crashes (double-free/wrong size) with third party libraries
Goto Forum:
  


Current Time: Mon May 13 17:56:18 CEST 2024

Total time taken to generate the page: 0.01328 seconds