Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Sharing some humour

Sharing some humour

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresperformancecareer
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leon de boer
    wrote on last edited by
    #1

    I was doing a job for a company and they don't allow memory allocations to be used you have to request a static block at program start from the memory management unit and then recycle that in your code. You want more there is a whole song and dance you must do. It was a complete pain and then they made the mistake of telling me I could use threads and you could request space for the thread ... so I did apply for 1 thread and got given it. I offer perhaps the funniest use of a thread ever ... in windows the code would look like this

    static BOOL ReleaseThread = FALSE;

    DWORD WINAPI MyThread (LPVOID lpParam){
    char buffer[4096];
    *(void**)lpParam = &buffer[0];
    do {} while (!ReleaseThread);
    return (0);
    }

    If you haven't worked it out here would be the equivalent windows use of the thread.

    char* buf = NULL;
    HANDLE myThread = CreateThread(0, 0, MyThread, &buf, 0, NULL);
    while (!buf) {};
    strcpy_s(buf, 4096, "Hello there stack buffer\r\n");
    printf("%s", buf);
    ReleaseThread = TRUE;

    But the best bit was it passed thru without anyone noticing.

    In vino veritas

    L D 2 Replies Last reply
    0
    • L leon de boer

      I was doing a job for a company and they don't allow memory allocations to be used you have to request a static block at program start from the memory management unit and then recycle that in your code. You want more there is a whole song and dance you must do. It was a complete pain and then they made the mistake of telling me I could use threads and you could request space for the thread ... so I did apply for 1 thread and got given it. I offer perhaps the funniest use of a thread ever ... in windows the code would look like this

      static BOOL ReleaseThread = FALSE;

      DWORD WINAPI MyThread (LPVOID lpParam){
      char buffer[4096];
      *(void**)lpParam = &buffer[0];
      do {} while (!ReleaseThread);
      return (0);
      }

      If you haven't worked it out here would be the equivalent windows use of the thread.

      char* buf = NULL;
      HANDLE myThread = CreateThread(0, 0, MyThread, &buf, 0, NULL);
      while (!buf) {};
      strcpy_s(buf, 4096, "Hello there stack buffer\r\n");
      printf("%s", buf);
      ReleaseThread = TRUE;

      But the best bit was it passed thru without anyone noticing.

      In vino veritas

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      leon de boer wrote:

      But the best bit was it passed thru without anyone noticing.

      Sounds like you are a program managers worse nightmare. :omg: Best Wishes, -David Delaune P.S. Wasn't me that downvoted you.

      L 1 Reply Last reply
      0
      • L Lost User

        leon de boer wrote:

        But the best bit was it passed thru without anyone noticing.

        Sounds like you are a program managers worse nightmare. :omg: Best Wishes, -David Delaune P.S. Wasn't me that downvoted you.

        L Offline
        L Offline
        leon de boer
        wrote on last edited by
        #3

        Haha yeah I would downvote myself :-) I figured I would get everything working before dealing with the buffer recycling. It takes a fair bit of work to track what buffers in use and where. What I laughed at was with all the rigor around memory handling I could do it and no-one raised an eyebrow. I mean that is a truely horrible idea. I will probably recycle one of my memory stream objects and donate it to them because I think the whole manual tracking of buffers is a bit naft and I think just as likely to create program errors as running out of memory.

        In vino veritas

        1 Reply Last reply
        0
        • L leon de boer

          I was doing a job for a company and they don't allow memory allocations to be used you have to request a static block at program start from the memory management unit and then recycle that in your code. You want more there is a whole song and dance you must do. It was a complete pain and then they made the mistake of telling me I could use threads and you could request space for the thread ... so I did apply for 1 thread and got given it. I offer perhaps the funniest use of a thread ever ... in windows the code would look like this

          static BOOL ReleaseThread = FALSE;

          DWORD WINAPI MyThread (LPVOID lpParam){
          char buffer[4096];
          *(void**)lpParam = &buffer[0];
          do {} while (!ReleaseThread);
          return (0);
          }

          If you haven't worked it out here would be the equivalent windows use of the thread.

          char* buf = NULL;
          HANDLE myThread = CreateThread(0, 0, MyThread, &buf, 0, NULL);
          while (!buf) {};
          strcpy_s(buf, 4096, "Hello there stack buffer\r\n");
          printf("%s", buf);
          ReleaseThread = TRUE;

          But the best bit was it passed thru without anyone noticing.

          In vino veritas

          D Offline
          D Offline
          Daniel Pfeffer
          wrote on last edited by
          #4

          leon de boer wrote:

          they don't allow memory allocations to be used you have to request a static block at program start from the memory management unit and then recycle that in your code.

          There are good reasons for that: 1. In many cases, it is better to discover that you don't have enough memory at program start than to discover it later. 2. In real-time systems, heap management time can be unpredictable. This makes achieving the time guarantees much more difficult.

          If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill

          L 1 Reply Last reply
          0
          • D Daniel Pfeffer

            leon de boer wrote:

            they don't allow memory allocations to be used you have to request a static block at program start from the memory management unit and then recycle that in your code.

            There are good reasons for that: 1. In many cases, it is better to discover that you don't have enough memory at program start than to discover it later. 2. In real-time systems, heap management time can be unpredictable. This makes achieving the time guarantees much more difficult.

            If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill

            L Offline
            L Offline
            leon de boer
            wrote on last edited by
            #5

            Sorry that is not correct ... running out of memory can be fatal no matter if you allocated it before hand or ran out of it on the heap. In my case I abused the stack which is just as bad. I am an embedded programmer and I live with low ram implementations in real time systems for a living, and that was the point of my joke at those who think you can frame protection in a standard or a formula. You can't, you need to frame intent and guidelines not specific implementations. You can not create a "safe" or "perfect" specification because you haven't written the code and you don't know the problems. That whole approach is like 1960's military code specifications and nightmare movie which failed dismally and nobody really codes that way anymore we all use block based approach. The first public discussion on the new military standards in software I know of was when Boeing allowed hackers to try and hack a "little bird" unmanned helicopter. If you don't know about this stuff that would be a good start point. Hacker-Proof Code Confirmed[^] As they said you can't hack it and is guaranteed to perform error-free, that isn't a claim it's a provable fact. There are links in the article to the research language F* (F-STAR) and the Project Everest which is Microsofts play in the area of trying to develop better hack free products. Most new high reliability stuff will follow down those paths for obvious reasons, they can offer guarantees something every other technique can't do.

            In vino veritas

            D L 2 Replies Last reply
            0
            • L leon de boer

              Sorry that is not correct ... running out of memory can be fatal no matter if you allocated it before hand or ran out of it on the heap. In my case I abused the stack which is just as bad. I am an embedded programmer and I live with low ram implementations in real time systems for a living, and that was the point of my joke at those who think you can frame protection in a standard or a formula. You can't, you need to frame intent and guidelines not specific implementations. You can not create a "safe" or "perfect" specification because you haven't written the code and you don't know the problems. That whole approach is like 1960's military code specifications and nightmare movie which failed dismally and nobody really codes that way anymore we all use block based approach. The first public discussion on the new military standards in software I know of was when Boeing allowed hackers to try and hack a "little bird" unmanned helicopter. If you don't know about this stuff that would be a good start point. Hacker-Proof Code Confirmed[^] As they said you can't hack it and is guaranteed to perform error-free, that isn't a claim it's a provable fact. There are links in the article to the research language F* (F-STAR) and the Project Everest which is Microsofts play in the area of trying to develop better hack free products. Most new high reliability stuff will follow down those paths for obvious reasons, they can offer guarantees something every other technique can't do.

              In vino veritas

              D Offline
              D Offline
              Daniel Pfeffer
              wrote on last edited by
              #6

              I stand corrected.

              If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill

              L 1 Reply Last reply
              0
              • D Daniel Pfeffer

                I stand corrected.

                If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill

                L Offline
                L Offline
                leon de boer
                wrote on last edited by
                #7

                You are party right any system is better than none ... I understood your intent :-) Our human systems are always flawed but yeah the new HDL synthesis tool stuff is scary good. Worth playing around with if you have the time and it's fun but quite different way of programming and probably not on Visual Studio until 2050 !!!!

                In vino veritas

                1 Reply Last reply
                0
                • L leon de boer

                  Sorry that is not correct ... running out of memory can be fatal no matter if you allocated it before hand or ran out of it on the heap. In my case I abused the stack which is just as bad. I am an embedded programmer and I live with low ram implementations in real time systems for a living, and that was the point of my joke at those who think you can frame protection in a standard or a formula. You can't, you need to frame intent and guidelines not specific implementations. You can not create a "safe" or "perfect" specification because you haven't written the code and you don't know the problems. That whole approach is like 1960's military code specifications and nightmare movie which failed dismally and nobody really codes that way anymore we all use block based approach. The first public discussion on the new military standards in software I know of was when Boeing allowed hackers to try and hack a "little bird" unmanned helicopter. If you don't know about this stuff that would be a good start point. Hacker-Proof Code Confirmed[^] As they said you can't hack it and is guaranteed to perform error-free, that isn't a claim it's a provable fact. There are links in the article to the research language F* (F-STAR) and the Project Everest which is Microsofts play in the area of trying to develop better hack free products. Most new high reliability stuff will follow down those paths for obvious reasons, they can offer guarantees something every other technique can't do.

                  In vino veritas

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Hi, I waited until the thread went beyond the first page to further engage with you. I can tell you why your employer has this requirement. This is common on mission-critical software. Exceptions and Stack Unwinding in C++[^] If you allocate memory on the stack... and a recoverable exception occurs in your thread... the memory is correctly released during stack unwinding. If you allocate memory on the heap and a recoverable exception occurs in your thread... the memory is not released and now your application potentially has a resource leak.

                  leon de boer wrote:

                  As they said you can't hack it and is guaranteed to perform error-free, that isn't a claim it's a provable fact.

                  This is not correct. I have met both Bryan Parno[^] and Jeannette Wing[^] and I was present at the 2014 presentation on campus at Redmond. Yes, small sections of logic can be statistically proven to be secure. It would not be correct to make the claim of "guaranteed to perform error-free, that isn't a claim it's a provable fact" If I were to assign a confidence level to what they have achieved I would say "High Confidence". Best Wishes, -David Delaune

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups