I miss my pointers [modified]
-
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
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)) -
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
-
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: :)
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 -
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
My dad's favorite expression was "Give me my horse". All depends on the generation.
-
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
you have to wait for C# v5.0
-
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
LINQ simulates it somehow. You can call a
Skip(i)
method and it will return anIEnumerable
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.
-
you have to wait for C# v5.0
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
-
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
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."
-
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
Obviously you missed this one: Please do not post programming questions here. If you have a programming question then click here[^]!. ;)
-
LINQ simulates it somehow. You can call a
Skip(i)
method and it will return anIEnumerable
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.
A SkipIterator (internal, System.Core.dll) is created.. You can look at it in Reflector.
-
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.
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.
-
A SkipIterator (internal, System.Core.dll) is created.. You can look at it in Reflector.
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.
-
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
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
-
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
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
-
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
I do believe our English members would use the phrase "cheeky bastard" here. :laugh:
Software Zen:
delete this;
Fold With Us![^]