I'm wondering if anyone can give me a good example of using pointers in C# in .Net and why you chose to use pointers?
+1
A:
If you wanted to do some performant image processing for a web application, you might want to consider using pointers there. See Image Processing Basics in C# on codeproject.com.
Mark Cidade
2009-04-08 17:42:18
+1 - Since his name is "madcolor" I suspect this might be exactly what he needs it for!
John Rasch
2009-04-08 17:51:07
+1
A:
You only need to use pointers if you're using unmanaged code, or making pinvoke calls.
Michael Meadows
2009-04-08 17:42:26
Strictly speaking, working with most unmanaged code is possible without using `unsafe` C# at all (by using `IntPtr`)
Mehrdad Afshari
2009-04-08 17:43:24
+5
A:
This isn't really a question to specific to ASP.NET.
If you are going to use pointers in .NET, the predominant reason is that you have an interop scenario where it is going to be easier to use pointers in unsafe code instead of IntPtr instances.
The second most popular (and distant) reason is because you might actually have a performance gain in processing large amounts of data in unsafe code than in managed code. Image processing algorithms are a good example of this.
casperOne
2009-04-08 17:42:53
Would you say a web app like http://aviary.com/home might be an example where pointers would be used?
madcolor
2009-04-08 17:56:33
@madcolor: That's impossible to say. Generally speaking, any web server or framework can serve up HTML, you don't even know for sure that it's ASP.NET that's doing the work, although it is a very safe bet given the viewstate fields in the page.
casperOne
2009-04-08 17:59:41
@madcolor: That being said, I'd say that it's not done with pointers. Generally, you are better off letting .NET and ASP.NET do the memory management for you, since it's going to be better at it (typically).
casperOne
2009-04-08 18:00:34