Hello,
currently I'm working on a company project where they have created a custom FileOpenDialog component.
In this component they have a function to get all the Physical drives on a system and return the free space.
At the moment this function is extremely slow. The original code use to take about 28 seconds to fetch all the information about the drives and display it on screen.
My function is able to do it in 14 seconds at the moment. But it's stll not fast enough. We are working remote with the application so it already goes slow due bandwirdth limitations and and I really want to increase the speed of the drive listing.
Below is the code written in C++.
If anyone is able to tell me how I can increase the performance of the call please let me know.
currently I'm working on a company project where they have created a custom FileOpenDialog component.
In this component they have a function to get all the Physical drives on a system and return the free space.
At the moment this function is extremely slow. The original code use to take about 28 seconds to fetch all the information about the drives and display it on screen.
My function is able to do it in 14 seconds at the moment. But it's stll not fast enough. We are working remote with the application so it already goes slow due bandwirdth limitations and and I really want to increase the speed of the drive listing.
Below is the code written in C++.
If anyone is able to tell me how I can increase the performance of the call please let me know.
Code:
CLogger::Logger()->LogMessage(Information, ":: Entering the refreshDrives Function ::"); bool bResult; char cDrive; WORD LastErrorMode; // Clear all drives from the listbox. lstBxDrives->Items->Clear(); // Supress the error box if no media is inserted in a drive. LastErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); // Fetch all the logical drivers currently configured on the system. DWORD Drives = GetLogicalDrives(); DWORD Mask = 1; CLogger::Logger()->LogMessage(Information, ":: Starting Drive Loop ::"); int start = GetTickCount(); // Iterate through the bitmap and fetch the information about the Drive. for(int i = 0; i < 25; ++i) { // Do not add the C Drive if the user is browsing local // and does not have the permission. if((i == 2) && !bFromArchive) { continue; } // Check if the drive exits. if(Drives & Mask) { // Prepare our variables for fetching the data we require. AnsiString DriveLetter = (AnsiString) char(i + int('A')) + ":\\"; unsigned __int64 nSizeBytes; char VolumeName[255] = "0"; // Get the free space on the volume bool SizeSuccess = ::GetDiskFreeSpaceEx(DriveLetter.c_str(), (PULARGE_INTEGER)&nSizeBytes, NULL, NULL); // Get the volume information. bool InfoSuccess = ::GetVolumeInformation(DriveLetter.c_str(), VolumeName, 255, NULL, NULL, NULL, NULL, 0); // Add the drive the listbox if it exits. if(InfoSuccess && SizeSuccess) { lstBxDrives->Items->Add(DriveLetter + " [" + AnsiString(VolumeName) + "] " + Utils::sizeToText(nSizeBytes) + " available"); } } // Shift our Mask one bit to the left. Mask <<= 1; } int end = GetTickCount(); CLogger::Logger()->LogMessage(Information, ":: Took " + AnsiString(end - start) + " ms to finish driveRefresh ::"); // Set the error supression back to the previous level. SetErrorMode(LastErrorMode); if (lstBxDrives->Items->Count > 0) { lstBxDrives->ItemIndex = 0; if ((lstBxDrives->ItemIndex == 0) && (!bFromArchive)) sLocalDirectory = sLocalRoot; else sLocalDirectory = lstBxDrives->Items->Strings[lstBxDrives->ItemIndex].SubString(1,3); lstBxDirectoryRefresh(); bResult = true; } else { BtBtnCancel->Click(); bResult = true; } ToolBar1->Enabled = bResult; return bResult;
Comment