1

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?

2
  • What do you mean by "using pointers", are you trying to call some unmanaged code? Commented Apr 8, 2009 at 17:39
  • I'm just learning about pointers and wondering how they might apply to web development. Since I'm working in .Net, I thought I'd limit it to that. Commented Apr 8, 2009 at 17:44

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Would you say a web app like aviary.com/home might be an example where pointers would be used?
@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.
@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).
1

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.

1 Comment

+1 - Since his name is "madcolor" I suspect this might be exactly what he needs it for!
1

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

1 Comment

Strictly speaking, working with most unmanaged code is possible without using unsafe C# at all (by using IntPtr)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.