Click here to Skip to main content
15,885,216 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralC++ & Thinking about SSD & wear level Pin
raddevus27-Mar-21 11:58
mvaraddevus27-Mar-21 11:58 
GeneralRe: C++ & Thinking about SSD & wear level (updated) Pin
Peter_in_278027-Mar-21 16:03
professionalPeter_in_278027-Mar-21 16:03 
GeneralRe: C++ & Thinking about SSD & wear level (updated) Pin
raddevus27-Mar-21 17:47
mvaraddevus27-Mar-21 17:47 
GeneralRe: C++ & Thinking about SSD & wear level (updated) Pin
David O'Neil28-Mar-21 3:29
professionalDavid O'Neil28-Mar-21 3:29 
GeneralRe: C++ & Thinking about SSD & wear level (updated) Pin
raddevus28-Mar-21 3:37
mvaraddevus28-Mar-21 3:37 
GeneralRe: C++ & Thinking about SSD & wear level Pin
David O'Neil28-Mar-21 4:14
professionalDavid O'Neil28-Mar-21 4:14 
GeneralRe: C++ & Thinking about SSD & wear level Pin
raddevus28-Mar-21 5:11
mvaraddevus28-Mar-21 5:11 
GeneralRe: C++ & Thinking about SSD & wear level Pin
David O'Neil28-Mar-21 11:56
professionalDavid O'Neil28-Mar-21 11:56 
Here's a version without the GCC specific code, and a more C++ approach to the thousands separator (not that I care for that - I always have to look it up and it is a pain).

For those who use it, you will need to set your project to Multi-byte.
C++
#include <windows.h>
<h1>include <iostream></h1>

<h1>include <locale></h1>

<h1>include <sysinfoapi.h></h1>

void getOsRunTime();

struct threes : std::numpunct<char> {
    std::string do_grouping() const { return "\3"; }
    // note: comma is provided by std::numpunct<char>
};

int main() { 
    HANDLE dev = CreateFile(LPCSTR("\\\\.\\C:"), 
        FILE_READ_ATTRIBUTES, 
        FILE_SHARE_READ | FILE_SHARE_WRITE, 
        NULL, 
        OPEN_EXISTING, 
        0, 
        NULL);

    DISK_PERFORMANCE disk_info { };
    DWORD bytes;

    if (dev == INVALID_HANDLE_VALUE) {
        std::cerr << "Error opening disk\n";
        return 1;
    }

    if (!DeviceIoControl(dev, 
            IOCTL_DISK_PERFORMANCE, 
            NULL, 
            0, 
            &disk_info, 
            sizeof(disk_info), 
            &bytes, 
            NULL))
    {
        std::cerr << "Failure in DeviceIoControl\n";
        return 1;
    }
    std::cout.imbue(std::locale(std::cout.getloc(), new threes));
    std::cout << "Bytes read: " << disk_info.BytesRead.QuadPart << "\n";
    std::cout << "Bytes read: " << disk_info.BytesRead.QuadPart << "\n";
    std::cout << "Bytes written: " << disk_info.BytesWritten.QuadPart << "\n";
    getOsRunTime();
}

void getOsRunTime(){
    ULONGLONG milli = GetTickCount64();
    //3600000 milliseconds in an hour
    long days = milli / (ULONGLONG)(3600000 *24);
    milli = milli - ((ULONGLONG)3600000 *24) * days;
    long hr = milli / 3600000;
    milli = milli - (ULONGLONG)3600000 * hr;
    //60000 milliseconds in a minute
    long min = milli / 60000;
    milli = milli - (ULONGLONG)60000 * min;

    //1000 milliseconds in a second
    long sec = milli / 1000;
    milli = milli - (ULONGLONG)1000 * sec;
    std::cout << "OS has been running " << days << " days " << hr << " hours " << min << " minutes " << sec << " seconds " << milli << " ms." << std::endl;
}

GeneralRe: C++ & Thinking about SSD & wear level Pin
raddevus28-Mar-21 12:50
mvaraddevus28-Mar-21 12:50 
GeneralRe: C++ & Thinking about SSD & wear level Pin
Dan Neely20-Apr-21 5:41
Dan Neely20-Apr-21 5:41 
GeneralAre you tired of keeping up with the latest changes? Pin
Slow Eddie20-Mar-21 2:58
professionalSlow Eddie20-Mar-21 2:58 
GeneralRe: Are you tired of keeping up with the latest changes? Pin
Julian Ragan20-Mar-21 3:22
Julian Ragan20-Mar-21 3:22 
GeneralRe: Are you tired of keeping up with the latest changes? Pin
GuyThiebaut24-Mar-21 0:32
professionalGuyThiebaut24-Mar-21 0:32 
GeneralRe: Are you tired of keeping up with the latest changes? Pin
Gary R. Wheeler5-May-21 14:20
Gary R. Wheeler5-May-21 14:20 
GeneralRe: Are you tired of keeping up with the latest changes? Pin
Super Lloyd5-May-21 15:11
Super Lloyd5-May-21 15:11 
GeneralRe: Are you tired of keeping up with the latest changes? Pin
obermd18-Aug-21 3:16
obermd18-Aug-21 3:16 
GeneralAbsolutely Horrific Pin
Brisingr Aerowing18-Mar-21 7:00
professionalBrisingr Aerowing18-Mar-21 7:00 
GeneralRe: Absolutely Horrific Pin
PIEBALDconsult18-Mar-21 7:13
mvePIEBALDconsult18-Mar-21 7:13 
GeneralRe: Absolutely Horrific Pin
Daniel Pfeffer18-Mar-21 7:43
professionalDaniel Pfeffer18-Mar-21 7:43 
GeneralRe: Absolutely Horrific Pin
Slow Eddie20-Mar-21 2:53
professionalSlow Eddie20-Mar-21 2:53 
GeneralRe: Absolutely Horrific Pin
Greg Utas18-Mar-21 8:17
professionalGreg Utas18-Mar-21 8:17 
GeneralRe: Absolutely Horrific Pin
obermd19-Mar-21 3:46
obermd19-Mar-21 3:46 
GeneralRe: Absolutely Horrific Pin
Greg Utas19-Mar-21 4:26
professionalGreg Utas19-Mar-21 4:26 
GeneralRe: Absolutely Horrific Pin
honey the codewitch27-Mar-21 12:43
mvahoney the codewitch27-Mar-21 12:43 
GeneralRe: Absolutely Horrific Pin
Greg Utas27-Mar-21 14:27
professionalGreg Utas27-Mar-21 14:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.