473,322 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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
Jul 16 '08 #1
12 993
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
Jul 16 '08 #2
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.

Jul 16 '08 #3
What does OP stand for?

Daniel

"Fernando Gómez" <fe****************@gmail.comwrote in message
news:On**************@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.

Jul 16 '08 #4
I wanted to use an object from the newer .NET namespace.

Daniel

"David Wilkinson" <no******@effisols.comwrote in message
news:us**************@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

Jul 16 '08 #5
If I use std::vector, would my code still be portable to other .NET runtimes
on top of other platforms?

Daniel

"David Wilkinson" <no******@effisols.comwrote in message
news:us**************@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

Jul 16 '08 #6
Daniel wrote:
What does OP stand for?

Daniel
Original Poster.
Jul 16 '08 #7
Daniel wrote:
I wanted to use an object from the newer .NET namespace.

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

Regards.
Jul 16 '08 #8
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<Tinstead, with an appropriate
value for T.
>
Regards.

Jul 16 '08 #9
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******@effisols.comwrote in message
news:us**************@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

Jul 16 '08 #10
Why use that instead of ArrayList?

Daniel

"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:uY**************@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<Tinstead, with an appropriate
value for T.
>>
Regards.


Jul 16 '08 #11
Daniel wrote:
Why use that instead of ArrayList?

Daniel

"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:uY**************@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<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.

Jul 17 '08 #12
Fernando Gómez wrote:
Daniel wrote:
>Why use that instead of ArrayList?

Daniel

"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:uY**************@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<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.
Jul 17 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: TF | last post by:
I have a fixed array of vectors like: vector<string> a_vStr; Then I grow each vector item and use it later. Everything works fine but I am curious about following potential problem. When we...
10
by: BCC | last post by:
Ive been googling and reading through my books but I haven't figured out a solution (much less an elegant one) to create a multidimensional array with a runtime determined number of dimensions. I...
49
by: vfunc | last post by:
If I have a large array 10,000+ elements then how do I reserve memory for this ? Currently I get a segmentation fault. Dynamic reservation is good, but allowing a chunk for the program is an...
20
by: Martin Jřrgensen | last post by:
Hi, I'm reading a number of double values from a file. It's a 2D-array: 1 2 3 4 5 6 7 ------------- 1 3.2 2 0 2.1 3 9.3 4
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
9
by: JoeC | last post by:
I am crating a new version of my map game and my map will be a 2d array. I had problems trying to create a 2d array dynamically, in fact C++ won't let me do it. My question is how to create the...
3
by: Matthias Pospiech | last post by:
I have an 2D vector array, but a function that can calculate only with 1D arrays. Now I need to pass every row of the 2D array to that function. So how can I pass a part (row or column) of a 2D...
7
by: hlg | last post by:
I have a question, which must surely have occurred to many programmers since STL first appeared, and yet I have found no reference to it anywhere, suggesting the problem is insoluble. Nevertheless,...
6
by: remlostime | last post by:
now, i write some code code1: int a; int main(){} code2: vector<inta(10000000); int main(){} after using g++ compile, and run it, code1 is broken, but code2 runs
2
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.