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

Re: use array or vector by David

David
Wed Jul 16 10:47:31 CDT 2008

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.public.vc.language.

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

--
David Wilkinson
Visual C++ MVP

Re: use array or vector by fernando

fernando
Wed Jul 16 11:30:06 CDT 2008

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.public.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::Collections.

Regards.


Re: use array or vector by Daniel

Daniel
Wed Jul 16 16:05:43 CDT 2008

What does OP stand for?

Daniel

"Fernando Gómez" <fernando.a.gomez.f@gmail.com> wrote in message
news:OnRJRE25IHA.1468@TK2MSFTNGP05.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.public.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::Collections.
>
> Regards.
>



Re: use array or vector by Daniel

Daniel
Wed Jul 16 16:06:25 CDT 2008

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

Daniel

"David Wilkinson" <no-reply@effisols.com> wrote in message
news:us7eBt15IHA.3480@TK2MSFTNGP03.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.public.vc.language.
>
> And the answer would have been: use std::vector.
>
> --
> David Wilkinson
> Visual C++ MVP



Re: use array or vector by Daniel

Daniel
Wed Jul 16 16:21:23 CDT 2008

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.com> wrote in message
news:us7eBt15IHA.3480@TK2MSFTNGP03.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.public.vc.language.
>
> And the answer would have been: use std::vector.
>
> --
> David Wilkinson
> Visual C++ MVP



Re: use array or vector by fernando

fernando
Wed Jul 16 16:35:37 CDT 2008

Daniel wrote:
> What does OP stand for?
>
> Daniel

Original Poster.

Re: use array or vector by fernando

fernando
Wed Jul 16 16:36:22 CDT 2008

Daniel wrote:
> I wanted to use an object from the newer .NET namespace.
>
> Daniel
>

Then you could use System::Collection::ArrayList.

Regards.

Re: use array or vector by Ben

Ben
Wed Jul 16 16:53:46 CDT 2008

Fernando Gómez wrote:
> Daniel wrote:
>> I wanted to use an object from the newer .NET namespace.
>>
>> Daniel
>>
>
> Then you could use System::Collection::ArrayList.

Don't use ArrayList in new code.

Use ::System::Collections::Generic::List<T> instead, with an appropriate
value for T.

>
> Regards.



Re: use array or vector by Ben

Ben
Wed Jul 16 16:55:32 CDT 2008

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.com> wrote in message
> news:us7eBt15IHA.3480@TK2MSFTNGP03.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.public.vc.language.
>>
>> And the answer would have been: use std::vector.
>>
>> --
>> David Wilkinson
>> Visual C++ MVP



Re: use array or vector by Daniel

Daniel
Wed Jul 16 17:31:44 CDT 2008

Why use that instead of ArrayList?

Daniel

"Ben Voigt [C++ MVP]" <rbv@nospam.nospam> wrote in message
news:uY9UG345IHA.1176@TK2MSFTNGP02.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::Collection::ArrayList.
>
> Don't use ArrayList in new code.
>
> Use ::System::Collections::Generic::List<T> instead, with an appropriate
> value for T.
>
>>
>> Regards.
>
>



Re: use array or vector by fernando

fernando
Wed Jul 16 19:03:44 CDT 2008

Daniel wrote:
> Why use that instead of ArrayList?
>
> Daniel
>
> "Ben Voigt [C++ MVP]" <rbv@nospam.nospam> wrote in message
> news:uY9UG345IHA.1176@TK2MSFTNGP02.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::Collection::ArrayList.
>> Don't use ArrayList in new code.
>>
>> Use ::System::Collections::Generic::List<T> instead, with an appropriate
>> value for T.
>>
>>> Regards.
>>
>
>
I'd guess that it is because List<T> is type safe, so you won't have to
cast from object to you your particular type, etc.


Re: use array or vector by Ben

Ben
Thu Jul 17 08:54:02 CDT 2008

Fernando Gómez wrote:
> Daniel wrote:
>> Why use that instead of ArrayList?
>>
>> Daniel
>>
>> "Ben Voigt [C++ MVP]" <rbv@nospam.nospam> wrote in message
>> news:uY9UG345IHA.1176@TK2MSFTNGP02.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::Collection::ArrayList.
>>> Don't use ArrayList in new code.
>>>
>>> Use ::System::Collections::Generic::List<T> instead, with an
>>> appropriate value for T.
>>>
>>>> Regards.
>>>
>>
>>
> I'd guess that it is because List<T> is 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.