none
C# or visual C++6 RRS feed

  • Question

  • I do not know if this is the right place to post this question or not but here it goes, i am creating a project that simulates parts of the environment by applying rules that are found in nature using calculations(lots of calculations i may say) and then representing it using brushes and filling rectangles this was done using visual c# 2008 (directx maybe used in the future for faster representation of the environment) one of my friends says that we should use visual c++6 and not visual c++ 2005 because its faster than visual c++ 2005 and than visual c# 2005 so i want to know if this is true as soon as possible, and is it feasible to still use visual c++6 to create a good user interface ??

    one of the functions used:
    class Rules
        {
            int[,] GrassMatrix = new int[50, 50];
             Random random = new Random();
          
            public void Intialize()
            {
                for (int i = 0; i < 50; i++)
                {
                    for (int j = 0; j < 50; j++)
                    {
                        GrassMatrix[i, j] = random.Next(255);
                     }
                }
            }
            public  int GrassFunction(int i, int j)
            {
                GrassMatrix[i, j] += (FertilityMatrix[i, j] - 127) / 35;

                if (TreesMatrix[i, j] > 127)
                {
                    GrassMatrix[i, j] += (TreesMatrix[i, j] - 127) / 35;

                }
                GrassMatrix[i, j] -= (DesertMatrix[i, j] - 127) / 22;
                GrassMatrix[i, j] -= (SnowyMatrix[i, j] - 127) / 20;

                GrassMatrix[i, j] += (RainMatrix[i, j] - 127) / 15;
                 //////////////////////////////////////////////////////////////////
                if (i > 0 && j > 0)
                {
                    GrassMatrix[i - 1, j - 1] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i > 0 && j < 49)
                {
                    GrassMatrix[i - 1, j + 1] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i < 49 && j >0)
                {
                    GrassMatrix[i + 1, j - 1] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i <49 && j < 49)
                {
                    GrassMatrix[i + 1, j + 1] += (GrassMatrix[i, j] - 127) / 35;
                }


                 if (i > 0)
                {
                    GrassMatrix[i - 1, j] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i < 49)
                {
                    GrassMatrix[i + 1, j] += (GrassMatrix[i, j] - 127) / 35;
                }
                 if(j > 0)
                 {
                     GrassMatrix[i, j - 1] += (GrassMatrix[i, j] - 127) / 35;
                 }
                 if (j < 49)
                 {
                     GrassMatrix[i, j + 1] += (GrassMatrix[i, j] - 127) / 35;
                 }
                 //////////////////////////////////////////////////////////////////
                if (GrassMatrix[i, j] > 255)
                {
                    GrassMatrix[i, j] = 255;
                }
                if (GrassMatrix[i, j] < 0)
                {
                    GrassMatrix[i, j] = 0;
                }

                return GrassMatrix[i, j];
            }
    and the method used to represent the data:
    for (int x = 0; x < 50; x++)
                    {
                        for (int y = 0; y < 50; y++)
                        {
                            SolidBrush GrassBrush = new SolidBrush(Color.FromArgb(R.GrassFunction(x, y), 0, 255, 0));
     Rectangle GrassRectangle = new Rectangle(posX + (10 * x), posY + (10 * y), 10, 10);
    g.FillRectangle(GrassBrush, GrassRectangle);
    GrassBrush.Dispose();
    }
    }
    I do not know if this is the right place to post this question or not but here it goes, i am creating a project that simulates parts of the environment by applying rules that are found in nature using calculations(lots of calculations i may say) and then representing it using brushes and filling rectangles this was done using visual c# 2008 (directx maybe used in the future for faster representation of the environment) one of my friends says that we should use visual c++6 and not visual c++ 2005 because its faster than visual c++ 2005 and than visual c# 2005 so i want to know if this is true as soon as possible, and is it feasible to still use visual c++6 to create a good user interface ??

    Here is a code sample done with  visual c# 2008:

    one of the functions used:
            public  int GrassFunction(int i, int j)
            {
                GrassMatrix[i, j] += (FertilityMatrix[i, j] - 127) / 35;

                if (TreesMatrix[i, j] > 127)
                {
                    GrassMatrix[i, j] += (TreesMatrix[i, j] - 127) / 35;

                }
                GrassMatrix[i, j] -= (DesertMatrix[i, j] - 127) / 22;
                GrassMatrix[i, j] -= (SnowyMatrix[i, j] - 127) / 20;

                GrassMatrix[i, j] += (RainMatrix[i, j] - 127) / 15;
                 //////////////////////////////////////////////////////////////////
                if (i > 0 && j > 0)
                {
                    GrassMatrix[i - 1, j - 1] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i > 0 && j < 49)
                {
                    GrassMatrix[i - 1, j + 1] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i < 49 && j >0)
                {
                    GrassMatrix[i + 1, j - 1] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i <49 && j < 49)
                {
                    GrassMatrix[i + 1, j + 1] += (GrassMatrix[i, j] - 127) / 35;
                }


                 if (i > 0)
                {
                    GrassMatrix[i - 1, j] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i < 49)
                {
                    GrassMatrix[i + 1, j] += (GrassMatrix[i, j] - 127) / 35;
                }
                 if(j > 0)
                 {
                     GrassMatrix[i, j - 1] += (GrassMatrix[i, j] - 127) / 35;
                 }
                 if (j < 49)
                 {
                     GrassMatrix[i, j + 1] += (GrassMatrix[i, j] - 127) / 35;
                 }
                 //////////////////////////////////////////////////////////////////
                if (GrassMatrix[i, j] > 255)
                {
                    GrassMatrix[i, j] = 255;
                }
                if (GrassMatrix[i, j] < 0)
                {
                    GrassMatrix[i, j] = 0;
                }

                return GrassMatrix[i, j];
            }
    Saturday, March 8, 2008 5:08 PM

Answers

  • Hi,

     

    Let's gonna clarify some things Smile

     

    1. Visual C++6 is native code only. The code generated with C++ 6.0 will be a native (or unmanaged) program.

    2. Visual C++ 2005 has two flavours. You can do a native C++ program or a C++/CLI program. A native C++ program done with Visual C++ 2005 will be at least as faster as the same program done with Visual C++ 6 (both are native programs).

    3. A C# or a C++/CLI program is a managed program, so it needs (and uses) the .NET Framework. Tipically .NET programs are slower than the native programs, althought in most cases this cannot be appreciated (even thought a .net program can run faster than a native one in some circumstancies).

    Remember: how you program has much more impact on the speed of your program than the technology you use!

     

    I don't recommend you to use Visual C++ 6. Visual C++ 2005 have the same capabilities, so you don't need Visual C++ 6.

    Creating a user interface with MFC (the native library that comes with Visual C++) is possible, buf its more work than create the same user interface using C# or C++/CLI (and the System.Windows.Forms namespace).

     

    Test your application with Visual C#, and if you are not happy with the speed, consider optimize the application first (check the best practices of C# programming, and revise your algorithms). If after an optimitzation you still are not happy, consider using C++, but does not expect a very impressive speed by only switching to C++. Do a proof of concept first!

     

    Regarding DirectX, there is no problem: you can use DirectX with native C++ (as always has been done), and you can use MDX (Managed DirectX) or the newer XNA Framework to use DirectX under C#.

     

    Hope this helps :-)

    Greetings

     

     

    Saturday, March 8, 2008 7:27 PM

All replies

  • I do not know if this is the right place to post this question or not but here it goes, i am creating a project that simulates parts of the environment by applying rules that are found in nature using calculations(lots of calculations i may say) and then representing it using brushes and filling rectangles this was done using visual c# 2008 (directx maybe used in the future for faster representation of the environment) one of my friends says that we should use visual c++6 and not visual c++ 2005 because its faster than visual c++ 2005 and than visual c# 2005 so i want to know if this is true as soon as possible, and is it feasible to still use visual c++6 to create a good user interface ??

    one of the functions used:
    class Rules
        {
            int[,] GrassMatrix = new int[50, 50];
             Random random = new Random();
          
            public void Intialize()
            {
                for (int i = 0; i < 50; i++)
                {
                    for (int j = 0; j < 50; j++)
                    {
                        GrassMatrix[i, j] = random.Next(255);
                     }
                }
            }
            public  int GrassFunction(int i, int j)
            {
                GrassMatrix[i, j] += (FertilityMatrix[i, j] - 127) / 35;

                if (TreesMatrix[i, j] > 127)
                {
                    GrassMatrix[i, j] += (TreesMatrix[i, j] - 127) / 35;

                }
                GrassMatrix[i, j] -= (DesertMatrix[i, j] - 127) / 22;
                GrassMatrix[i, j] -= (SnowyMatrix[i, j] - 127) / 20;

                GrassMatrix[i, j] += (RainMatrix[i, j] - 127) / 15;
                 //////////////////////////////////////////////////////////////////
                if (i > 0 && j > 0)
                {
                    GrassMatrix[i - 1, j - 1] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i > 0 && j < 49)
                {
                    GrassMatrix[i - 1, j + 1] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i < 49 && j >0)
                {
                    GrassMatrix[i + 1, j - 1] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i <49 && j < 49)
                {
                    GrassMatrix[i + 1, j + 1] += (GrassMatrix[i, j] - 127) / 35;
                }


                 if (i > 0)
                {
                    GrassMatrix[i - 1, j] += (GrassMatrix[i, j] - 127) / 35;
                }
                if (i < 49)
                {
                    GrassMatrix[i + 1, j] += (GrassMatrix[i, j] - 127) / 35;
                }
                 if(j > 0)
                 {
                     GrassMatrix[i, j - 1] += (GrassMatrix[i, j] - 127) / 35;
                 }
                 if (j < 49)
                 {
                     GrassMatrix[i, j + 1] += (GrassMatrix[i, j] - 127) / 35;
                 }
                 //////////////////////////////////////////////////////////////////
                if (GrassMatrix[i, j] > 255)
                {
                    GrassMatrix[i, j] = 255;
                }
                if (GrassMatrix[i, j] < 0)
                {
                    GrassMatrix[i, j] = 0;
                }

                return GrassMatrix[i, j];
            }
    and the method used to represent the data:
    for (int x = 0; x < 50; x++)
                    {
                        for (int y = 0; y < 50; y++)
                        {
                            SolidBrush GrassBrush = new SolidBrush(Color.FromArgb(R.GrassFunction(x, y), 0, 255, 0));
     Rectangle GrassRectangle = new Rectangle(posX + (10 * x), posY + (10 * y), 10, 10);
    g.FillRectangle(GrassBrush, GrassRectangle);
    GrassBrush.Dispose();
    }
    }
    Saturday, March 8, 2008 5:05 PM
  • Hi,

     

    Let's gonna clarify some things Smile

     

    1. Visual C++6 is native code only. The code generated with C++ 6.0 will be a native (or unmanaged) program.

    2. Visual C++ 2005 has two flavours. You can do a native C++ program or a C++/CLI program. A native C++ program done with Visual C++ 2005 will be at least as faster as the same program done with Visual C++ 6 (both are native programs).

    3. A C# or a C++/CLI program is a managed program, so it needs (and uses) the .NET Framework. Tipically .NET programs are slower than the native programs, althought in most cases this cannot be appreciated (even thought a .net program can run faster than a native one in some circumstancies).

    Remember: how you program has much more impact on the speed of your program than the technology you use!

     

    I don't recommend you to use Visual C++ 6. Visual C++ 2005 have the same capabilities, so you don't need Visual C++ 6.

    Creating a user interface with MFC (the native library that comes with Visual C++) is possible, buf its more work than create the same user interface using C# or C++/CLI (and the System.Windows.Forms namespace).

     

    Test your application with Visual C#, and if you are not happy with the speed, consider optimize the application first (check the best practices of C# programming, and revise your algorithms). If after an optimitzation you still are not happy, consider using C++, but does not expect a very impressive speed by only switching to C++. Do a proof of concept first!

     

    Regarding DirectX, there is no problem: you can use DirectX with native C++ (as always has been done), and you can use MDX (Managed DirectX) or the newer XNA Framework to use DirectX under C#.

     

    Hope this helps :-)

    Greetings

     

     

    Saturday, March 8, 2008 7:27 PM