Wednesday, December 30, 2009

Windows API Calls

Right,

so at the moment I'm working as a Junior C++ software Engineer. Really enjoying the job, but that's not what todays post will be about.

Currently I'm working on a project that should be able to fetch all the Drives on a system and display the VolumeName and FreeSpace on those Drives.
To make this as fast as possible, I'm using direct API calls to the Windows API. According to alot of people and sites this should be the fastest way to get the information I need, but it is still taking up to 14 seconds before I even get a response from the application.
I understand that there could be a small delay due the act I have 2 network drives that need to be accessed and that this could take up time.

To test this I made a VCL C++ version and a Visual C++ .NET application to test this. When I run the code from the .NET application on my laptop this goes instantly. If I run the same code on the development PC this also takes a long time to complete. So at the moment I still blame the Network Drives.

The code I'm using at the moment is the following:

// Fetch the Drives from the System
array^ allDrives = DriveInfo::GetDrives();
// Iterate through the array and check if the drive is ready.
// If it is ready then create a display string and add it to the listbox.
for(int i = 0; i <>Length; ++i)
{
if(allDrives[i]->IsReady)
{
String^ drive = allDrives[i]->Name;
drive += " [";
drive += allDrives[i]->VolumeLabel;
drive += "] , ";
__int64 size = allDrives[i]->AvailableFreeSpace / (1024 * 1024 * 1024);
drive += size.ToString();
drive += " GB available.";
// add the drive to the listbox.
lstDrives->Items->Add(drive);
}
}
So I'm still a but clueless as to why the real slowdown is occuring in this code on my development PC (Windows Server 2003) opposed to my laptop (Windows XP).....