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. The Lounge
  3. C++ is love

C++ is love

Scheduled Pinned Locked Moved The Lounge
csharpc++
86 Posts 24 Posters 11 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.
  • R Rick York

    John Lennon said, "All you need is love."

    "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

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

    And look what happened to him

    Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

    1 Reply Last reply
    0
    • honey the codewitchH honey the codewitch

      No, that's basically how my code works.

      Real programmers use butterflies

      Sander RosselS Offline
      Sander RosselS Offline
      Sander Rossel
      wrote on last edited by
      #49

      In that case you may be related to Tom Jomes[^] :D

      Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript

      1 Reply Last reply
      0
      • honey the codewitchH honey the codewitch

        I'm economically agnostic. No systems devised by humans survive contact with them.

        Real programmers use butterflies

        D Offline
        D Offline
        den2k88
        wrote on last edited by
        #50

        I'm gonna reuse the heck out of this sentence.

        GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

        1 Reply Last reply
        0
        • J Jorgen Andersson

          Sounds like you're in regression. Next year you'll be hot for C and after that you'll start a club with Codewraith doing 1802 assembler for your own Zwölf.

          Wrong is evil and must be defeated. - Jeff Ello Never stop dreaming - Freddie Kruger

          D Offline
          D Offline
          den2k88
          wrote on last edited by
          #51

          That would make 3 people in the club - though I usually prefer C to assembler, I like a good delve into the madness from time to time.

          GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

          1 Reply Last reply
          0
          • honey the codewitchH honey the codewitch

            Then that would be an actual garbage collector, which I'm trying to avoid. :-D Actually what I'm doing is kind of clever. I allow you to allocate a "MemoryPool" on the heap or the stack, and then allocate memory from that pool. It does not allow you to delete. However, all allocated segments are always contiguous and sequential, leading to a number of performance advantages. Instead of deleting single allocations you can freeAll() to reset/recycle the entire pool and invalidate the memory therein. It's actually quite nice for a lot of basic processing scenarios. it's just inefficient for mutable data where sizes can change - which it's not designed for.

            Real programmers use butterflies

            J Offline
            J Offline
            Johann Gerell
            wrote on last edited by
            #52

            That's what AAA games use (and maybe non-AAA too, I only know what DICE did, as I worked there) - arena allocators. When a level starts, it allocates from its own "arena", and when the level is done, the arena is wiped. Lessens the risk of memory leaks and gives full control and trackability of all allocations.

            Time you enjoy wasting is not wasted time - Bertrand Russel

            1 Reply Last reply
            0
            • honey the codewitchH honey the codewitch

              I'm economically agnostic. No systems devised by humans survive contact with them.

              Real programmers use butterflies

              S Offline
              S Offline
              Slacker007
              wrote on last edited by
              #53

              honey the codewitch wrote:

              I'm economically agnostic

              that is a copout, and you know it. ;)

              honey the codewitchH 1 Reply Last reply
              0
              • Greg UtasG Greg Utas

                When I saw your post, I wondered how badly you were going to get flamed, given the popularity of C# on this site. I never thought this thread would stay so civilized, let alone be fairly positive. :)

                Robust Services Core | Software Techniques for Lemmings | Articles
                The fox knows many things, but the hedgehog knows one big thing.

                N Offline
                N Offline
                Nelek
                wrote on last edited by
                #54

                The day is not over yet. :rolleyes: :laugh:

                M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                1 Reply Last reply
                0
                • honey the codewitchH honey the codewitch

                  Okay that's fair, except I can't think of much I can't get to in C++ with the right massaging of the compiler. I can manually build vtbls, i can make call stack frames myself, typically, I can even drop to inline assembly if I really want. So I see it more as giving you more tools than ASM. I don't think it takes anything away.

                  Real programmers use butterflies

                  Greg UtasG Offline
                  Greg UtasG Offline
                  Greg Utas
                  wrote on last edited by
                  #55

                  Make your own vtbls and call stack frames? Do tell. When do you find this useful? My naughtiest code changed an object's class at runtime by changing its vptr. The two classes in question had a common base class and owned other objects, so this avoided a messy deep copy and fixing pointers to the morphed object. I wonder how many OO languages could do that.

                  Robust Services Core | Software Techniques for Lemmings | Articles
                  The fox knows many things, but the hedgehog knows one big thing.

                  <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                  <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                  honey the codewitchH 1 Reply Last reply
                  0
                  • W W Balboos GHB

                    Some of the references warn against its use. So far as I can tell, it's based upon usage and gotcha's that are common in C - in other words, C is for grownup who take responsibility for their actions. Simply put - know what you're doing when you do it. Don't free() it - well, duh! That's the point of using it. Beware of stack overflows. Always keep your wits about you with memory usage. Don't use in recursive functions or loops. In a loop, index the allocations into an array of pointers, or, if you want to reuse the same one, allocate it before the loop . . . just like the other memory functions. Seems standard enough - for the grownups in the room

                    Ravings en masse^

                    "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

                    "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

                    U Offline
                    U Offline
                    User 13269747
                    wrote on last edited by
                    #56

                    Quote:

                    Some of the references warn against its use. Simply put - know what you're doing when you do it. Don't free() it - well, duh! That's the point of using it. Beware of stack overflows. Always keep your wits about you with memory usage. Don't use in recursive functions or loops. In a loop, index the allocations into an array of pointers, or, if you want to reuse the same one, allocate it before the loop . . . just like the other memory functions. Seems standard enough - for the grownups in the room

                    Don't use alloca(), it's not part of the C standard.

                    W 1 Reply Last reply
                    0
                    • honey the codewitchH honey the codewitch

                      GitHub - codewitch-honey-crisis/MemoryPool: Small fixed size sequential memory pool allocators for constrained memory environments[^] :laugh:

                      Real programmers use butterflies

                      U Offline
                      U Offline
                      User 13269747
                      wrote on last edited by
                      #57

                      Would you mind if I gave you a small critique on that code?

                      honey the codewitchH 1 Reply Last reply
                      0
                      • U User 13269747

                        Quote:

                        Some of the references warn against its use. Simply put - know what you're doing when you do it. Don't free() it - well, duh! That's the point of using it. Beware of stack overflows. Always keep your wits about you with memory usage. Don't use in recursive functions or loops. In a loop, index the allocations into an array of pointers, or, if you want to reuse the same one, allocate it before the loop . . . just like the other memory functions. Seems standard enough - for the grownups in the room

                        Don't use alloca(), it's not part of the C standard.

                        W Offline
                        W Offline
                        W Balboos GHB
                        wrote on last edited by
                        #58

                        I read that too; mentioned it somewhere in this thread. That would be like "Don't Use that Graphics Library - it's not part of the C Standard".*

                        Ravings en masse^

                        "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

                        "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

                        D 1 Reply Last reply
                        0
                        • W W Balboos GHB

                          I read that too; mentioned it somewhere in this thread. That would be like "Don't Use that Graphics Library - it's not part of the C Standard".*

                          Ravings en masse^

                          "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

                          "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

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

                          Only use code that runs as expected on the [DeathStation 9000](https://enacademic.com/dic.nsf/enwiki/2748465)!

                          Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                          W K 2 Replies Last reply
                          0
                          • U User 13269747

                            Would you mind if I gave you a small critique on that code?

                            honey the codewitchH Offline
                            honey the codewitchH Offline
                            honey the codewitch
                            wrote on last edited by
                            #60

                            go ahead. my C++ is rusty so I'm sure there's stuff to be improved.

                            Real programmers use butterflies

                            U M 2 Replies Last reply
                            0
                            • Greg UtasG Greg Utas

                              Make your own vtbls and call stack frames? Do tell. When do you find this useful? My naughtiest code changed an object's class at runtime by changing its vptr. The two classes in question had a common base class and owned other objects, so this avoided a messy deep copy and fixing pointers to the morphed object. I wonder how many OO languages could do that.

                              Robust Services Core | Software Techniques for Lemmings | Articles
                              The fox knows many things, but the hedgehog knows one big thing.

                              honey the codewitchH Offline
                              honey the codewitchH Offline
                              honey the codewitch
                              wrote on last edited by
                              #61

                              The call stack frames can be useful for doing things like method logging frameworks The vtbl manipulation is useful if your making a library to do hardcore COM interop

                              Real programmers use butterflies

                              1 Reply Last reply
                              0
                              • S Slacker007

                                honey the codewitch wrote:

                                I'm economically agnostic

                                that is a copout, and you know it. ;)

                                honey the codewitchH Offline
                                honey the codewitchH Offline
                                honey the codewitch
                                wrote on last edited by
                                #62

                                It's not. It's the truth. I'm married to a communist, but that doesn't make me one.

                                Real programmers use butterflies

                                S 1 Reply Last reply
                                0
                                • D Daniel Pfeffer

                                  Only use code that runs as expected on the [DeathStation 9000](https://enacademic.com/dic.nsf/enwiki/2748465)!

                                  Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                                  W Offline
                                  W Offline
                                  W Balboos GHB
                                  wrote on last edited by
                                  #63

                                  (fill in clever retort of your choice)                  Ravings en masse^

                                  "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

                                  "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

                                  J 1 Reply Last reply
                                  0
                                  • honey the codewitchH honey the codewitch

                                    go ahead. my C++ is rusty so I'm sure there's stuff to be improved.

                                    Real programmers use butterflies

                                    U Offline
                                    U Offline
                                    User 13269747
                                    wrote on last edited by
                                    #64

                                    Not much improvement, just a few observations: 1. Identifiers starting with underscores are reserved. If you use them then your program is non-conforming for no good reason. 2. The comparison against capacity in both the static and dynamic classes result in never being able to use the last byte of the pool: The "used()>=capacity" should be "used()>capacity". To test it instantiate a pool of 10 bytes and allocate 6. The (capacity() - used()) is then 4, but a further allocation of 4 fails. A further allocation of 3, on the other hand, succeeds and (capacity() - used()) is then 1. 3. The static pool could benefit from a #warning directive when C is too large. Right now a 8MB C when instantiating it (1024 * 1024 * 8) would almost certainly overflow the stack, and 8MB is not a lot of memory.

                                    honey the codewitchH M 2 Replies Last reply
                                    0
                                    • U User 13269747

                                      Not much improvement, just a few observations: 1. Identifiers starting with underscores are reserved. If you use them then your program is non-conforming for no good reason. 2. The comparison against capacity in both the static and dynamic classes result in never being able to use the last byte of the pool: The "used()>=capacity" should be "used()>capacity". To test it instantiate a pool of 10 bytes and allocate 6. The (capacity() - used()) is then 4, but a further allocation of 4 fails. A further allocation of 3, on the other hand, succeeds and (capacity() - used()) is then 1. 3. The static pool could benefit from a #warning directive when C is too large. Right now a 8MB C when instantiating it (1024 * 1024 * 8) would almost certainly overflow the stack, and 8MB is not a lot of memory.

                                      honey the codewitchH Offline
                                      honey the codewitchH Offline
                                      honey the codewitch
                                      wrote on last edited by
                                      #65

                                      1. I thought they were only reserved for globals. I stand corrected. 2. Good catch. 3. The static pool can and often is declared as a global, making it heap/not stack, which is where it's primarily designed to go. DynamicMemoryPool is probably a better choice if you need a locally scoped pool because it always allocates from the heap. Thanks!

                                      Real programmers use butterflies

                                      1 Reply Last reply
                                      0
                                      • D den2k88

                                        W∴ Balboos, GHB wrote:

                                        I'd presume it used the stack for memory.

                                        Yep, exactly. I had the habit of making objects "stackable" whenever possible, for example strings had fixed size straight into the struct, so the whole object was a single contiguous dataspace easily allocatable in the stack and passed around with a memcpy. Of course it isn't alwasy the best option but I like it when it is.

                                        GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                                        K Offline
                                        K Offline
                                        Kirk 10389821
                                        wrote on last edited by
                                        #66

                                        I had a programmer who was notorious for declaring char somestr[256]; and RETURNING somestr out of the function to be used by others. "But it runs fine in the debugger" was his last refrain... LOL

                                        honey the codewitchH 1 Reply Last reply
                                        0
                                        • honey the codewitchH honey the codewitch

                                          It's not. It's the truth. I'm married to a communist, but that doesn't make me one.

                                          Real programmers use butterflies

                                          S Offline
                                          S Offline
                                          Slacker007
                                          wrote on last edited by
                                          #67

                                          honey the codewitch wrote:

                                          I'm married to a communist

                                          I shudder at the thought.

                                          honey the codewitchH 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