tags:

views:

425

answers:

3

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
+1 - Since his name is "madcolor" I suspect this might be exactly what he needs it for!
John Rasch
+1  A: 

You only need to use pointers if you're using unmanaged code, or making pinvoke calls.

Michael Meadows
Strictly speaking, working with most unmanaged code is possible without using `unsafe` C# at all (by using `IntPtr`)
Mehrdad Afshari
+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
Would you say a web app like http://aviary.com/home might be an example where pointers would be used?
madcolor
@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
@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
Cool.. Good Info.
madcolor