Jump to content
  • Advertisement
Sign in to follow this  
Sagar_Indurkhya

C# pointer thingy

This topic is 5049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am building a neural network app. Here is my plan: I am going to have an 10000 array of neurons. My first question: How do I get a pointer to this array?
Neuron[] n = new Neuron[10000];
I know in C++, I could just get a pointer to first element, but in C#, the garbage collector moves stuff around. Thanx

Share this post


Link to post
Share on other sites
Advertisement
I looked at the optimizations the JIT compiler performs, and it turns out that my NeuralNetwork and Neuron class would probably be super optimized with a c++ compiler. Can someone explain this thing about code interoperability? I want to write two classes in C++, super optimize them into a dll or something, and then access them from my C# code.

Share this post


Link to post
Share on other sites
The best way is probably to write the library in unmanaged C++, then write a wrapper in managed C++ and use that with your C# application.

At least that's what I do for my server.

Share this post


Link to post
Share on other sites
That seems like a good idea, except, won't the wrapper class have a performance hit? Also, is there any way to get the C# compiler to do a super JIT Optimization at compile time?

Share this post


Link to post
Share on other sites
Quote:
Original post by Sagar_Indurkhya
That seems like a good idea, except, won't the wrapper class have a performance hit? Also, is there any way to get the C# compiler to do a super JIT Optimization at compile time?


I am not sure in your situation, but I didn't see a performance hit, it was actually the other way around.

I actually tried building the full server application in C# and lost some performance compared to my hybrid approach. Obviously there is a small hit when interfacing the unmanaged C++ with managed C++.. but the thing is that is was still faster than having the full application written in C#. All of my performance and time critical functions are in unmanaged C++.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sagar_Indurkhya
I am building a neural network app. Here is my plan:

I am going to have an 10000 array of neurons. My first question:
How do I get a pointer to this array?

What do you need a pointer to the array for?

Share this post


Link to post
Share on other sites
Without getting into why you need this and if it's actually a good idea...you want to use the "fixed" statement.

Check out the MSDN reference.

Epolevne

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!