use array or vector

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel

    use array or vector

    I need to use arrays that I can dimension during runtime. Is there a way to
    do that in VC++ .NET using arrays, or would I need to use vectors instead?

    Daniel


  • David Wilkinson

    #2
    Re: use array or vector

    Daniel wrote:
    I need to use arrays that I can dimension during runtime. Is there a way to
    do that in VC++ .NET using arrays, or would I need to use vectors instead?
    Daniel:

    If this is a question about standard C++, you should have asked it in
    microsoft.publi c.vc.language.

    And the answer would have been: use std::vector.

    --
    David Wilkinson
    Visual C++ MVP

    Comment

    • =?UTF-8?B?RmVybmFuZG8gR8OzbWV6?=

      #3
      Re: use array or vector

      David Wilkinson wrote:
      Daniel wrote:
      >I need to use arrays that I can dimension during runtime. Is there a
      >way to do that in VC++ .NET using arrays, or would I need to use
      >vectors instead?
      >
      Daniel:
      >
      If this is a question about standard C++, you should have asked it in
      microsoft.publi c.vc.language.
      >
      And the answer would have been: use std::vector.
      >
      Or perhaps CArray (well, the OP didn't specify the library he was
      using). Or something from System::Collect ions.

      Regards.

      Comment

      • Daniel

        #4
        Re: use array or vector

        What does OP stand for?

        Daniel

        "Fernando Gómez" <fernando.a.gom ez.f@gmail.comw rote in message
        news:OnRJRE25IH A.1468@TK2MSFTN GP05.phx.gbl...
        David Wilkinson wrote:
        >Daniel wrote:
        >>I need to use arrays that I can dimension during runtime. Is there a
        >>way to do that in VC++ .NET using arrays, or would I need to use vectors
        >>instead?
        >>
        >Daniel:
        >>
        >If this is a question about standard C++, you should have asked it in
        >microsoft.publ ic.vc.language.
        >>
        >And the answer would have been: use std::vector.
        >>
        >
        Or perhaps CArray (well, the OP didn't specify the library he was using).
        Or something from System::Collect ions.
        >
        Regards.
        >

        Comment

        • Daniel

          #5
          Re: use array or vector

          I wanted to use an object from the newer .NET namespace.

          Daniel

          "David Wilkinson" <no-reply@effisols. comwrote in message
          news:us7eBt15IH A.3480@TK2MSFTN GP03.phx.gbl...
          Daniel wrote:
          >I need to use arrays that I can dimension during runtime. Is there a way
          >to do that in VC++ .NET using arrays, or would I need to use vectors
          >instead?
          >
          Daniel:
          >
          If this is a question about standard C++, you should have asked it in
          microsoft.publi c.vc.language.
          >
          And the answer would have been: use std::vector.
          >
          --
          David Wilkinson
          Visual C++ MVP

          Comment

          • Daniel

            #6
            Re: use array or vector

            If I use std::vector, would my code still be portable to other .NET runtimes
            on top of other platforms?

            Daniel

            "David Wilkinson" <no-reply@effisols. comwrote in message
            news:us7eBt15IH A.3480@TK2MSFTN GP03.phx.gbl...
            Daniel wrote:
            >I need to use arrays that I can dimension during runtime. Is there a way
            >to do that in VC++ .NET using arrays, or would I need to use vectors
            >instead?
            >
            Daniel:
            >
            If this is a question about standard C++, you should have asked it in
            microsoft.publi c.vc.language.
            >
            And the answer would have been: use std::vector.
            >
            --
            David Wilkinson
            Visual C++ MVP

            Comment

            • =?ISO-8859-1?Q?Fernando_G=F3mez?=

              #7
              Re: use array or vector

              Daniel wrote:
              What does OP stand for?
              >
              Daniel
              Original Poster.

              Comment

              • =?ISO-8859-1?Q?Fernando_G=F3mez?=

                #8
                Re: use array or vector

                Daniel wrote:
                I wanted to use an object from the newer .NET namespace.
                >
                Daniel
                >
                Then you could use System::Collect ion::ArrayList.

                Regards.

                Comment

                • Ben Voigt [C++ MVP]

                  #9
                  Re: use array or vector

                  Fernando Gómez wrote:
                  Daniel wrote:
                  >I wanted to use an object from the newer .NET namespace.
                  >>
                  >Daniel
                  >>
                  >
                  Then you could use System::Collect ion::ArrayList.
                  Don't use ArrayList in new code.

                  Use ::System::Colle ctions::Generic ::List<Tinstead , with an appropriate
                  value for T.
                  >
                  Regards.

                  Comment

                  • Ben Voigt [C++ MVP]

                    #10
                    Re: use array or vector

                    Daniel wrote:
                    If I use std::vector, would my code still be portable to other .NET
                    runtimes on top of other platforms?
                    C++ code for .NET is only portable if
                    (1) You are using VC2005 or newer
                    (2) You pass /clr:pure, which disallows a lot of native stuff. Whether
                    std::vector still works I can't say, it may even depend on the type you are
                    using it with.
                    >
                    Daniel
                    >
                    "David Wilkinson" <no-reply@effisols. comwrote in message
                    news:us7eBt15IH A.3480@TK2MSFTN GP03.phx.gbl...
                    >Daniel wrote:
                    >>I need to use arrays that I can dimension during runtime. Is there
                    >>a way to do that in VC++ .NET using arrays, or would I need to use
                    >>vectors instead?
                    >>
                    >Daniel:
                    >>
                    >If this is a question about standard C++, you should have asked it in
                    >microsoft.publ ic.vc.language.
                    >>
                    >And the answer would have been: use std::vector.
                    >>
                    >--
                    >David Wilkinson
                    >Visual C++ MVP

                    Comment

                    • Daniel

                      #11
                      Re: use array or vector

                      Why use that instead of ArrayList?

                      Daniel

                      "Ben Voigt [C++ MVP]" <rbv@nospam.nos pamwrote in message
                      news:uY9UG345IH A.1176@TK2MSFTN GP02.phx.gbl...
                      Fernando Gómez wrote:
                      >Daniel wrote:
                      >>I wanted to use an object from the newer .NET namespace.
                      >>>
                      >>Daniel
                      >>>
                      >>
                      >Then you could use System::Collect ion::ArrayList.
                      >
                      Don't use ArrayList in new code.
                      >
                      Use ::System::Colle ctions::Generic ::List<Tinstead , with an appropriate
                      value for T.
                      >
                      >>
                      >Regards.
                      >
                      >

                      Comment

                      • =?ISO-8859-1?Q?Fernando_G=F3mez?=

                        #12
                        Re: use array or vector

                        Daniel wrote:
                        Why use that instead of ArrayList?
                        >
                        Daniel
                        >
                        "Ben Voigt [C++ MVP]" <rbv@nospam.nos pamwrote in message
                        news:uY9UG345IH A.1176@TK2MSFTN GP02.phx.gbl...
                        >Fernando Gómez wrote:
                        >>Daniel wrote:
                        >>>I wanted to use an object from the newer .NET namespace.
                        >>>>
                        >>>Daniel
                        >>>>
                        >>Then you could use System::Collect ion::ArrayList.
                        >Don't use ArrayList in new code.
                        >>
                        >Use ::System::Colle ctions::Generic ::List<Tinstead , with an appropriate
                        >value for T.
                        >>
                        >>Regards.
                        >>
                        >
                        >
                        I'd guess that it is because List<Tis type safe, so you won't have to
                        cast from object to you your particular type, etc.

                        Comment

                        • Ben Voigt [C++ MVP]

                          #13
                          Re: use array or vector

                          Fernando Gómez wrote:
                          Daniel wrote:
                          >Why use that instead of ArrayList?
                          >>
                          >Daniel
                          >>
                          >"Ben Voigt [C++ MVP]" <rbv@nospam.nos pamwrote in message
                          >news:uY9UG345I HA.1176@TK2MSFT NGP02.phx.gbl.. .
                          >>Fernando Gómez wrote:
                          >>>Daniel wrote:
                          >>>>I wanted to use an object from the newer .NET namespace.
                          >>>>>
                          >>>>Daniel
                          >>>>>
                          >>>Then you could use System::Collect ion::ArrayList.
                          >>Don't use ArrayList in new code.
                          >>>
                          >>Use ::System::Colle ctions::Generic ::List<Tinstead , with an
                          >>appropriate value for T.
                          >>>
                          >>>Regards.
                          >>>
                          >>
                          >>
                          I'd guess that it is because List<Tis type safe, so you won't have
                          to cast from object to you your particular type, etc.
                          And additionally far more efficient when used with value types, because it
                          doesn't require boxing and unboxing operations, inlines better, etc.


                          Comment

                          Working...