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. I miss my pointers [modified]

I miss my pointers [modified]

Scheduled Pinned Locked Moved The Lounge
csharpc++comdata-structuresarchitecture
20 Posts 17 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.
  • C Chris Maunder

    I'm doing one of those classic "scan an array, find an element, and return the elements from that element on" things and suddenly hit a roadblock: how do a &(array[i]) in C#? :sigh: [Edit: OK, so next time I clearly need to add a joke icon. No, I'm not asking for help. Just reminiscing. :sigh:2]

    cheers, Chris Maunder

    CodeProject.com : C++ MVP

    modified on Saturday, November 15, 2008 4:36 PM

    U Offline
    U Offline
    User of Users Group
    wrote on last edited by
    #3

    This is more of a result of bad design on the part of C# team, range concepts, decent iterators, and reverse 'enumeration' are the most glaring and obvious, put mildly, screw-ups while they were copying Java. You have to resort to all sort of things such as copying, messy yield compiler generation, and it still ends up insufficient. You can always do the pointer arithmetic as part of class (as that's all you get:-) : You can mark the variable or method 'unsafe'and then use 'fixed', you can go further but it is usually best practice not to let it leak out beyond a type, modern C++ libraries do that pretty good. unsafe fixed int _d[SOME_DOLLARS]; unsafe public double this[int index] get { fixed (int* d = _d ) return d[index]; } Before someone screams, as they probably missed the fact that there is plenty of it done in all or any decent scientific and engineering .NET commercial libraries known to man, including the oldest and best graphics library for CLR too. The disclaimer: Comparing perf between this, for, or foreach, or LINQ won't tell you the entire story as it will vary dramatically for 'non-classics', ie. specific scenario.. And jitted IL pointer code can surprise overall, but if you ask C# people: "It (re:everything) is not a CSharp idiom". I wonder what is, just the language name? Ah.. Still doesn't solve your problem as you want a pair, with a second as end iterator really.

    P 1 Reply Last reply
    0
    • C Chris Maunder

      I'm doing one of those classic "scan an array, find an element, and return the elements from that element on" things and suddenly hit a roadblock: how do a &(array[i]) in C#? :sigh: [Edit: OK, so next time I clearly need to add a joke icon. No, I'm not asking for help. Just reminiscing. :sigh:2]

      cheers, Chris Maunder

      CodeProject.com : C++ MVP

      modified on Saturday, November 15, 2008 4:36 PM

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

      You could go low-level and use unsafe code (pointers just like in C), or you could go higher-level and use an ArrayList, where you have the GetRange() method that returns a 'view' on a range of elements - modifications in that view will affect the underlying ArrayList. However, for some reason Microsoft doesn't support that feature in the generic List<T> - in the generic List, GetRange just returns a shallow copy. You'll have to use a library (e.g. C5[^]) if you want sane collections for C#. (or just create your own collection class to represent a part of an array)

      1 Reply Last reply
      0
      • C Chris Maunder

        I'm doing one of those classic "scan an array, find an element, and return the elements from that element on" things and suddenly hit a roadblock: how do a &(array[i]) in C#? :sigh: [Edit: OK, so next time I clearly need to add a joke icon. No, I'm not asking for help. Just reminiscing. :sigh:2]

        cheers, Chris Maunder

        CodeProject.com : C++ MVP

        modified on Saturday, November 15, 2008 4:36 PM

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #5

        Chris Maunder wrote:

        how do a &(array[i]) in C#?

        Assuming you have a struct array, you can do 'ref array[i]' where the method sig is foo(ref mystruct s).

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 beta 1 - out now!
        ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

        1 Reply Last reply
        0
        • C Chris Maunder

          I'm doing one of those classic "scan an array, find an element, and return the elements from that element on" things and suddenly hit a roadblock: how do a &(array[i]) in C#? :sigh: [Edit: OK, so next time I clearly need to add a joke icon. No, I'm not asking for help. Just reminiscing. :sigh:2]

          cheers, Chris Maunder

          CodeProject.com : C++ MVP

          modified on Saturday, November 15, 2008 4:36 PM

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #6

          The way you are looking up data seems more suited towards using a LinkedList (or using LINQ with IEnumerable<T> ).

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 beta 1 - out now!
          ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

          1 Reply Last reply
          0
          • C Chris Maunder

            I'm doing one of those classic "scan an array, find an element, and return the elements from that element on" things and suddenly hit a roadblock: how do a &(array[i]) in C#? :sigh: [Edit: OK, so next time I clearly need to add a joke icon. No, I'm not asking for help. Just reminiscing. :sigh:2]

            cheers, Chris Maunder

            CodeProject.com : C++ MVP

            modified on Saturday, November 15, 2008 4:36 PM

            D Offline
            D Offline
            DaveX86
            wrote on last edited by
            #7

            I never liked pointers...I have a mental block about them...every time I see a '*' or an '&' before something I break out in a cold sweat. It was a piece of mercy that the C# team put them behind the curtain where they belong :sigh: :)

            P 1 Reply Last reply
            0
            • D DaveX86

              I never liked pointers...I have a mental block about them...every time I see a '*' or an '&' before something I break out in a cold sweat. It was a piece of mercy that the C# team put them behind the curtain where they belong :sigh: :)

              P Offline
              P Offline
              Perspx
              wrote on last edited by
              #8

              I think they're useful at times, but pointer arithmetic can become a bit of a drag. But as you say it was cleary a benefit for C# to do away with them, except for in certain circumstances. Regards, --Persxp

              "A refund for defective software might be nice, except it would bankrupt the entire software industry in the first year."
              -Andrew Tanenbaum
              "Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer."
              -Fred Brooks

              1 Reply Last reply
              0
              • C Chris Maunder

                I'm doing one of those classic "scan an array, find an element, and return the elements from that element on" things and suddenly hit a roadblock: how do a &(array[i]) in C#? :sigh: [Edit: OK, so next time I clearly need to add a joke icon. No, I'm not asking for help. Just reminiscing. :sigh:2]

                cheers, Chris Maunder

                CodeProject.com : C++ MVP

                modified on Saturday, November 15, 2008 4:36 PM

                M Offline
                M Offline
                Member 4194593
                wrote on last edited by
                #9

                My dad's favorite expression was "Give me my horse". All depends on the generation.

                1 Reply Last reply
                0
                • C Chris Maunder

                  I'm doing one of those classic "scan an array, find an element, and return the elements from that element on" things and suddenly hit a roadblock: how do a &(array[i]) in C#? :sigh: [Edit: OK, so next time I clearly need to add a joke icon. No, I'm not asking for help. Just reminiscing. :sigh:2]

                  cheers, Chris Maunder

                  CodeProject.com : C++ MVP

                  modified on Saturday, November 15, 2008 4:36 PM

                  C Offline
                  C Offline
                  Chris Losinger
                  wrote on last edited by
                  #10

                  you have to wait for C# v5.0

                  image processing toolkits | batch image processing

                  J 1 Reply Last reply
                  0
                  • C Chris Maunder

                    I'm doing one of those classic "scan an array, find an element, and return the elements from that element on" things and suddenly hit a roadblock: how do a &(array[i]) in C#? :sigh: [Edit: OK, so next time I clearly need to add a joke icon. No, I'm not asking for help. Just reminiscing. :sigh:2]

                    cheers, Chris Maunder

                    CodeProject.com : C++ MVP

                    modified on Saturday, November 15, 2008 4:36 PM

                    L Offline
                    L Offline
                    Lutoslaw
                    wrote on last edited by
                    #11

                    LINQ simulates it somehow. You can call a Skip(i) method and it will return an IEnumerable which starts at the specified index.

                    Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

                    E 1 Reply Last reply
                    0
                    • C Chris Losinger

                      you have to wait for C# v5.0

                      image processing toolkits | batch image processing

                      J Offline
                      J Offline
                      Jim Crafton
                      wrote on last edited by
                      #12

                      Is that the new C++ 98 release?

                      ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! VCF Blog

                      E 1 Reply Last reply
                      0
                      • J Jim Crafton

                        Is that the new C++ 98 release?

                        ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! VCF Blog

                        E Offline
                        E Offline
                        El Corazon
                        wrote on last edited by
                        #13

                        Jim Crafton wrote:

                        Is that the new C++ 98 release?

                        It's okay, they've a plan to have all of C++2009 in place in C# by 2025. So they will eventually catch up. ;) (just don't plot the future graph of that)

                        _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb) John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."

                        1 Reply Last reply
                        0
                        • C Chris Maunder

                          I'm doing one of those classic "scan an array, find an element, and return the elements from that element on" things and suddenly hit a roadblock: how do a &(array[i]) in C#? :sigh: [Edit: OK, so next time I clearly need to add a joke icon. No, I'm not asking for help. Just reminiscing. :sigh:2]

                          cheers, Chris Maunder

                          CodeProject.com : C++ MVP

                          modified on Saturday, November 15, 2008 4:36 PM

                          M Offline
                          M Offline
                          Mladen Jankovic
                          wrote on last edited by
                          #14

                          Obviously you missed this one: Please do not post programming questions here. If you have a programming question then click here[^]!. ;)

                          [Genetic Algorithm Library]

                          1 Reply Last reply
                          0
                          • L Lutoslaw

                            LINQ simulates it somehow. You can call a Skip(i) method and it will return an IEnumerable which starts at the specified index.

                            Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

                            E Offline
                            E Offline
                            elektrowolf
                            wrote on last edited by
                            #15

                            A SkipIterator (internal, System.Core.dll) is created.. You can look at it in Reflector.

                            L 1 Reply Last reply
                            0
                            • U User of Users Group

                              This is more of a result of bad design on the part of C# team, range concepts, decent iterators, and reverse 'enumeration' are the most glaring and obvious, put mildly, screw-ups while they were copying Java. You have to resort to all sort of things such as copying, messy yield compiler generation, and it still ends up insufficient. You can always do the pointer arithmetic as part of class (as that's all you get:-) : You can mark the variable or method 'unsafe'and then use 'fixed', you can go further but it is usually best practice not to let it leak out beyond a type, modern C++ libraries do that pretty good. unsafe fixed int _d[SOME_DOLLARS]; unsafe public double this[int index] get { fixed (int* d = _d ) return d[index]; } Before someone screams, as they probably missed the fact that there is plenty of it done in all or any decent scientific and engineering .NET commercial libraries known to man, including the oldest and best graphics library for CLR too. The disclaimer: Comparing perf between this, for, or foreach, or LINQ won't tell you the entire story as it will vary dramatically for 'non-classics', ie. specific scenario.. And jitted IL pointer code can surprise overall, but if you ask C# people: "It (re:everything) is not a CSharp idiom". I wonder what is, just the language name? Ah.. Still doesn't solve your problem as you want a pair, with a second as end iterator really.

                              P Offline
                              P Offline
                              Pete OHanlon
                              wrote on last edited by
                              #16

                              I'm not sure it is missing the point. While I agree that C# isn't terribly efficient with regards to pointers (read not efficient there at all) it does have it's uses. To get LOB apps out the door in double quick time, .NET is very hard to beat. Before you get all bent out of shape, you should remember that my background is C/C++, so there's a load of features I'd love to see make the crossover, the simple fact is they are targetting two different types of applications. Bottom line - .NET is quicker to code, but C++ code is quicker to run.

                              Deja View - the feeling that you've seen this post before.

                              My blog | My articles | MoXAML PowerToys

                              1 Reply Last reply
                              0
                              • E elektrowolf

                                A SkipIterator (internal, System.Core.dll) is created.. You can look at it in Reflector.

                                L Offline
                                L Offline
                                Lutoslaw
                                wrote on last edited by
                                #17

                                elektrowolf wrote:

                                A SkipIterator (internal, System.Core.dll) is created.. You can look at it in Reflector.

                                Oh really? I was so sure that it creates a PointerIterator. What a suprise! :laugh:

                                Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

                                1 Reply Last reply
                                0
                                • C Chris Maunder

                                  I'm doing one of those classic "scan an array, find an element, and return the elements from that element on" things and suddenly hit a roadblock: how do a &(array[i]) in C#? :sigh: [Edit: OK, so next time I clearly need to add a joke icon. No, I'm not asking for help. Just reminiscing. :sigh:2]

                                  cheers, Chris Maunder

                                  CodeProject.com : C++ MVP

                                  modified on Saturday, November 15, 2008 4:36 PM

                                  R Offline
                                  R Offline
                                  Roger Wright
                                  wrote on last edited by
                                  #18

                                  There's a 12-step program to help people who miss their pointers. I'd give you a contact, but I've misplaced the address and can't remember where I stored it. I'll get back to you when I run across a reference to it.

                                  "A Journey of a Thousand Rest Stops Begins with a Single Movement"

                                  modified on Sunday, November 16, 2008 12:50 AM

                                  C G 2 Replies Last reply
                                  0
                                  • R Roger Wright

                                    There's a 12-step program to help people who miss their pointers. I'd give you a contact, but I've misplaced the address and can't remember where I stored it. I'll get back to you when I run across a reference to it.

                                    "A Journey of a Thousand Rest Stops Begins with a Single Movement"

                                    modified on Sunday, November 16, 2008 12:50 AM

                                    C Offline
                                    C Offline
                                    Chris Maunder
                                    wrote on last edited by
                                    #19

                                    Roger Wright wrote:

                                    I'll get back to you when I run across a reference to it

                                    Oh that's bad. That's really bad.

                                    cheers, Chris Maunder

                                    CodeProject.com : C++ MVP

                                    1 Reply Last reply
                                    0
                                    • R Roger Wright

                                      There's a 12-step program to help people who miss their pointers. I'd give you a contact, but I've misplaced the address and can't remember where I stored it. I'll get back to you when I run across a reference to it.

                                      "A Journey of a Thousand Rest Stops Begins with a Single Movement"

                                      modified on Sunday, November 16, 2008 12:50 AM

                                      G Offline
                                      G Offline
                                      Gary R Wheeler
                                      wrote on last edited by
                                      #20

                                      I do believe our English members would use the phrase "cheeky bastard" here. :laugh:

                                      Software Zen: delete this;
                                      Fold With Us![^]

                                      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