In windows os i want to get maximum reclaimable bytes, I am using shrink querymax command in diskpart tool to get maximum reclaimable bytes but that taking more time, is there way to get same using c++ instead of depending on tool
How to get maximum number of reclaimable bytes in windows
132 views Asked by Dinesh Chowdary At
        	2
        	
        There are 2 answers
0
                
                        
                            
                        
                        
                            On
                            
                            
                                                    
                    
                Use this:
#include <windows.h>
#include <psapi.h>
#include <iostream>
int main() {
    PROCESS_MEMORY_COUNTERS pmc;
    if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
        SIZE_T peakWorkingSetSize = pmc.PeakWorkingSetSize;
        SIZE_T currentWorkingSetSize = pmc.WorkingSetSize;
        std::cout << "Peak Working Set Size: " << peakWorkingSetSize << " bytes\n";
        std::cout << "Current Working Set Size: " << currentWorkingSetSize << " bytes\n";
        // Calculate reclaimable bytes
        SIZE_T reclaimableBytes = peakWorkingSetSize - currentWorkingSetSize;
        std::cout << "Reclaimable Bytes: " << reclaimableBytes << " bytes\n";
    } else {
        std::cerr << "Error getting process memory information.\n";
    }
    return 0;
}
The difference between the peak and current working set sizes can give you an estimate of the maximum number of reclaimable bytes.
There are Win32 APIs, like
IVdsVolumeShrink::QueryMaxReclaimableSee hereThey are Windows specific rather than portable C++.