Community
    • Login

    Ownership Model for pointer data?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    20 Posts 9 Posters 900 Views
    Loading More Posts
    • 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.
    • David Brigden52D
      David Brigden52 @dinkumoil
      last edited by

      @dinkumoil

      VB Script:

      With objGun
      .aimAt objFoot
      .shoot

      Windows Scripting Host error 80004005

      1 Reply Last reply Reply Quote 1
      • TBugReporterT
        TBugReporter @dinkumoil
        last edited by

        @dinkumoil
        Thank you for making me feel old, and also for giving me a good laugh. Every time I come across a copy of that list, I can’t resist trying to read it - and giggling so much that I have to stop reading (to resume breathing) before I get halfway thru. 🥲

        EkopalypseE 1 Reply Last reply Reply Quote 1
        • EkopalypseE
          Ekopalypse @TBugReporter
          last edited by

          I can’t resist trying to read it

          me too :-D

          1 Reply Last reply Reply Quote 1
          • Mark OlsonM
            Mark Olson @dinkumoil
            last edited by Mark Olson

            @dinkumoil
            dogescript

            classy Gun
                such shoot much target
                    very bullets is dis giv bullets
                    rly bullets giv length is 0
                        plz console.error with 'such empty, must reload, wow'
                        amaze
                    wow
                    very bullet is bullets dose pop
                    plz console.loge with "BANG!"
                    plz target.beShot with bullet
                wow
                
                maker bullets
                    dis giv bullets is bullets
                wow
                
            wow
            
            classy Bullet
                maker caliber
                    dis giv caliber is caliber
                wow
            wow
            
            classy Foot
                such beShot much bullet
                    plz console.loge with "OUCH!"
                wow
            wow
            
            very bullet is new Bullet with 45
            very gun is new Gun with [bullet]
            very foot is new Foot
            gun dose shoot with foot
            gun dose shoot with foot
            
            1 Reply Last reply Reply Quote 1
            • xzaton jwX
              xzaton jw @Alan Kilborn
              last edited by

              @Alan-Kilborn

              Writing any compiled language you don’t “know” whats going on inside the computer, you just reason about what it “should” do based on the abstract machine. You don’t know what machine code is generated until you look at the assembler for a given platform :)

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn @xzaton jw
                last edited by Alan Kilborn

                @xzaton-jw

                You don’t know what machine code is generated until you look at the assembler for a given platform

                Can’t argue with that…but it isn’t really related to the discussion earlier.

                Your original statement:

                I come from modern C++ so this is already really weird and sketchy style code.

                This is irksome because what @dinkumoil described is really fundamental, and (is one point of many that) should be what everyone learns before handing their trust off to something like “modern C++”. So many people don’t know this, or gloss over it.

                I have a good friend that goes on and on about how he loves C++, but he hates C because he just “doesn’t understand that stuff”. I just shake my head…

                But, I suppose by virtue of this thread, more of us have answers and the learning process has begun! Cheers!

                1 Reply Last reply Reply Quote 0
                • xzaton jwX
                  xzaton jw @dinkumoil
                  last edited by

                  @dinkumoil

                  I appreciate the answer, thankyou!

                  However, I disagree with your premise for why its this way:

                  You’re postulating that if ::SendMessage took ownership of the data, it:

                  • Wouldn’t be able to free it because it wouldn’t know when the caller is done with it (UAF)
                  • Potentially doesn’t point to the start of a block, so you end up leaking memory because it doesn’t clean it all up properly

                  That’s literally the point of ownership semantics, you can:

                  • signal it is the callee’s responsibility to clean up when they’re done so no copies need to be made.
                  • signal its not the callee’s responsibility because you’re doing some weird slicing type shit and they can never clean it up properly.

                  And in the case that both areas may need to access the data again, you use something like std::shared_ptr so its a reference counted shared ownership.

                  So yes, you can do API’s where you transfer ownership of the pointed to data, and they work really well since you’re skipping redundant copies. This isn’t something you can just work out with logical deduction, you either have it or you don’t, and if you don’t, its a bad API.

                  Its just a shame its written in C so I get fuckin weirdos coming out the woodwork telling me how silly I am because I’m asking questions about stuff they themselves don’t even understand, but I suppose that’s just par for the course when it comes to asking for help in programming forums lol.

                  PeterJonesP Alan KilbornA dinkumoilD Lycan ThropeL 4 Replies Last reply Reply Quote -1
                  • PeterJonesP
                    PeterJones @xzaton jw
                    last edited by PeterJones

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • Alan KilbornA
                      Alan Kilborn @xzaton jw
                      last edited by Alan Kilborn

                      @xzaton-jw said in Ownership Model for pointer data?:

                      fuckin weirdos

                      I suppose that’s me. I’ll wear that banner with pride, I guess.
                      Or maybe since it was a direct reply to @dinkumoil , maybe him as well…

                      stuff they themselves don’t even understand

                      …right…

                      To be fair, though, your reply does seem to indicate that you have more knowledge than my poor friend. So that’s good. :-)

                      1 Reply Last reply Reply Quote 1
                      • dinkumoilD
                        dinkumoil @xzaton jw
                        last edited by

                        @xzaton-jw said in Ownership Model for pointer data?:

                        fuckin weirdos

                        Even if you got some harsh criticism, you should not escalate the debate even more by being rude, only to be the bigger badass. Let’s stay civilized.

                        you can do API’s where you transfer ownership of the pointed to data

                        I’m pretty sure this can be done, but this was not what your question was about. You asked about the behaviour of the SendMessage function, i.e. the Win32 API. As I told you, this is a C API and C doesn’t provide integrated mechanisms to create an API that works like you prefer it.

                        you either have it or you don’t, and if you don’t, its a bad API

                        Just complaining about facts that you can not change and nobody else will change (or do you think MS decides to change the basic principles of the Win32 API after more than 3 decades?) makes no sense. Accept how it is, try to understand its basic principles and learn how to use it.

                        Its just a shame its written in C

                        I hope even future operating systems, released by MS or some other company, will have a C based API because C is a high-level programming language that provides only the absolute necessary grade of abstraction from the hardware. Thus, I like to call it a “high-level assembly language”. A C based API allows all other programming languages to use that API. It’s much more difficult to achieve this with a C++ based API because all programming languages would have to be compatible with C++ at the ABI level.

                        If a higher grade of abstraction from the hardware and the OS API (i.e. Win32) is needed, a framework can provide that. AFAIK, the ATL and MFC frameworks provided by MS don’t do a good job in this regard, but I’m not a C++ dev, so I’m not qualified to make any informed statements about that.

                        Lycan ThropeL 1 Reply Last reply Reply Quote 4
                        • Lycan ThropeL
                          Lycan Thrope @dinkumoil
                          last edited by Lycan Thrope

                          @dinkumoil said in Ownership Model for pointer data?:

                          I hope even future operating systems, released by MS or some other company, will have a C based API because C is a high-level programming language that provides only the absolute necessary grade of abstraction from the hardware. Thus, I like to call it a “high-level assembly language”. A C based API allows all other programming languages to use that API. It’s much more difficult to achieve this with a C++ based API because all programming languages would have to be compatible with C++ at the ABI level.

                          I’m glad you brought this up. This is exactly what C has been promoted as for years; that it is the next closest language to the metal as you can get short of Assembly Language, without being solely locked to a specific processor. dBASE is an older language and can use the Win32API, precisely for this language allowing us to extend it ourselves if the development vendor ever stopped supporting it. That’s why most FOSS is based on Linux and C. Processor Agnostic

                          The OP seems to be whining more about having to learn how to do what he wants without having to learn how the machinery works. How Millenial of him. I’ll be waiting with baited breath to see how he rewrites the Win32 API in C++, so he can do what he wants, unhindered by archaic languages. :)

                          1 Reply Last reply Reply Quote 2
                          • Lycan ThropeL
                            Lycan Thrope @xzaton jw
                            last edited by

                            @xzaton-jw said in Ownership Model for pointer data?:

                            Its just a shame its written in C so I get fuckin weirdos coming out the woodwork telling me how silly I am because I’m asking questions about stuff they themselves don’t even understand, but I suppose that’s just par for the course when it comes to asking for help in programming forums lol.

                            By the way, this isn’t a programming forum. This is the Notepad++ Community Forum. Not everyone that uses this forum is a programmer, they are users that use the program for diverse reasons, but then again, you seem to have gotten that wrong as well. Care to try for 3 out of 3?

                            1 Reply Last reply Reply Quote 1
                            • xzaton jwX
                              xzaton jw
                              last edited by xzaton jw

                              This is hard work, all I wanted to know is if I should clear up the data myself, or if the function will do it for me.

                              If the answer was just:

                              “It uses the Win32 API which doesn’t take ownership, you need to allocate and deallocate it yourself”

                              I’d have been happy and on my merry way. Instead I get a thread of garbage.

                              Anyway:

                              @dinkumoil said in Ownership Model for pointer data?:

                              Even if you got some harsh criticism, you should not escalate the debate even more by being rude, only to be the bigger badass. Let’s stay civilized.

                              Fair point

                              @dinkumoil said in Ownership Model for pointer data?:

                              As I told you, this is a C API and C doesn’t provide integrated mechanisms to create an API that works like you prefer it.

                              You could:

                              1. SendMessageTakeOwnership(raw_ptr*), SendMessageBorrow(raw_ptr*)
                              2. enum OWNERSHIP{BORROWS, TAKES_OWNWERSHP};
                                SendMessage(OWNERSHIP, raw_ptr*)

                              And likely a host of other ways of doing it. Ofcourse they aren’t as robust as other ways of doing it, but the point is you can do it in C.

                              I want to make a another point here, backwards compatibility is an amazing benefit, but it is not free. If there was a way to re-engineer the C API with the knowledge we have about software development today (and it was no effort to do so), I think it would be different to how it is now, and it would include a notion of functions either taking ownership or not.

                              The simple fact is that its easier/cheaper to document, and not break old code, than to break it to improve it. I think this is the main reason for why it is the way it is, not because they got it perfect first time around.

                              @dinkumoil said in Ownership Model for pointer data?:

                              AFAIK, the ATL and MFC frameworks

                              The fact MS tried to create a framework ontop of the C API demonstrates that it isn’t without its flaws.

                              @dinkumoil said in Ownership Model for pointer data?:

                              Just complaining about facts that you can not change and nobody else will change (or do you think MS decides to change the basic principles of the Win32 API after more than 3 decades?) makes no sense. Accept how it is, try to understand its basic principles and learn how to use it.

                              Fair point

                              @Lycan-Thrope said in Ownership Model for pointer data?:

                              The OP seems to be whining more about having to learn how to do what he wants without having to learn how the machinery works. How Millenial of him. I’ll be waiting with baited breath to see how he rewrites the Win32 API in C++, so he can do what he wants, unhindered by archaic languages. :)

                              I wanted to know how it worked to work around it to achieve what I was trying to do. The post is “what is the ownership model?”, not why “why is the ownership model bad?”, its a subtle difference so no surprise a boomer missed it.

                              @Lycan-Thrope said in Ownership Model for pointer data?:

                              By the way, this isn’t a programming forum. This is the Notepad++ Community Forum.

                              … being pedantic about this is just sad

                              Lycan ThropeL 1 Reply Last reply Reply Quote 0
                              • Lycan ThropeL
                                Lycan Thrope @xzaton jw
                                last edited by Lycan Thrope

                                @xzaton-jw said in Ownership Model for pointer data?:

                                I wanted to know how it worked to work around it to achieve what I was trying to do. The post is “what is the ownership model?”, not why “why is the ownership model bad?”, its a subtle difference so no surprise a boomer missed it.

                                Considering that the subject of “Ownership Model” is a fairly new aspect specific to “objects”, and C was never written to be Object based or Object Oriented, but is used to create Object-Based and Object-Oriented languages, your lack of knowledge is definitively ‘millenial’ (do it for me, or let me appear superior). C++ was written to extend C into an Object-Oriented language, by it’s very existence as stated by the developer:

                                Stroustrup is best known for his work on C++. In 1979, he began developing C++ (initially called "C with Classes"). - Bjarne Stroustrup via Wikipedia

                                Reading further into that same document you’ll find this particularly potent fact about C++ right at the top of the definition of the concepts of C++:

                                The key language-technical areas of contribution of C++ are:

                                A static type system with equal support for built-in types and user-defined types (that requires control of the construction, destruction, copying, and movement of objects; and operator overloading). - Wikipedia C++

                                This, my dear millenial, is called research, and it is what boomer’s learned to do early in life so they didn’t have to be hand held through their learning processes. This is what defines ‘independence’ as opposed to ‘dependence on others’ for answers.

                                @xzaton-jw said in Ownership Model for pointer data?:

                                … being pedantic about this is just sad

                                …as is being asinine.

                                Fini.

                                xzaton jwX 1 Reply Last reply Reply Quote 1
                                • xzaton jwX
                                  xzaton jw @Lycan Thrope
                                  last edited by

                                  @Lycan-Thrope

                                  There may genuinely be some confusion, let me clarify, when I talk about ownership semantics, I specifically mean:

                                  Who is responsible for “cleaning up” any resource which must be “freed” after it has been “acquired”?

                                  Its part of all languages, whether is a GC, or done manually. It could be dynamic memory, or some I/O like a file or network port. All this stuff about it being related to OOP is nonsense, but I can see why you thought that because RAII is an excellent way to handle it.

                                  As an example, look here: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessage

                                  Literally an example of passing ownership of a buffer in the win32 API.

                                  And listen man, programming is hard and asking questions is ok because it gives people a chance to learn something new.

                                  Maybe you should save your comments about working everything out on your own for places other than a forum?

                                  And while im here, everytime you’ve used stackoverflow, you’re being a hypocrite, because if it isn’t you asking for help, it’s you benefitting from someone else asking.

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post
                                  The Community of users of the Notepad++ text editor.
                                  Powered by NodeBB | Contributors