Dynamic arrays not really dynamic in managec C++? 
Author Message
 Dynamic arrays not really dynamic in managec C++?

E{*filter*}d by the promise of "dynamic arrays", I wrote a bunch of code like
this::

__gc class MyClass {
    Object* array [];

    MyClass() {
        array = new Object* [0];
    }

    void MorePlease(Object* o) {
        array->Add(o);       // throws exception:  Collection was of a fixed
size
    }

Quote:
};

Did I misunderstand what "dynamic" means?  How can I get one that is truly
extensible?

Thanks,

Steve



Thu, 08 Jul 2004 08:46:11 GMT  
 Dynamic arrays not really dynamic in managec C++?
Stephen,

Quote:
> E{*filter*}d by the promise of "dynamic arrays", I wrote a bunch of code like
> this::

Well, I must admit that's the first time I've heard that term used in
relation to MC++.

Quote:

> __gc class MyClass {
>     Object* array [];

>     MyClass() {
>         array = new Object* [0];
>     }

>     void MorePlease(Object* o) {
>         array->Add(o);       // throws exception:  Collection was of a
fixed
> size
>     }
> };

> Did I misunderstand what "dynamic" means?  How can I get one that is truly
> extensible?

Well, arrays in .NET (not only in MC++) are not really extensible, at least
for now, in this sense. As usual, one would use a wrapper class, which in
this case would be ArrayList or one of the other collection classes in
System::Collections.

--
Tomas Restrepo



Thu, 08 Jul 2004 10:40:37 GMT  
 Dynamic arrays not really dynamic in managec C++?
Tomas,

Quote:
> Stephen,
> > E{*filter*}d by the promise of "dynamic arrays", I wrote a bunch of code like
> > this::

> Well, I must admit that's the first time I've heard that term used in
> relation to MC++.

Well the Managed Extensions Reference uses the term:  "A __gc array is a
dynamic array that is allocated on the common language runtime heap."   But
what really mislead me is that __gc arrays inherit from System::Array and
actually do have methods like Add().  It just so happens that the
IsFixedSize property is always false (as far as I can tell, though I have
not found that fact in the docs).

Quote:

> > __gc class MyClass {
> >     Object* array [];

> >     MyClass() {
> >         array = new Object* [0];
> >     }

> >     void MorePlease(Object* o) {
> >         array->Add(o);       // throws exception:  Collection was of a
> fixed
> > size
> >     }
> > };

> > Did I misunderstand what "dynamic" means?  How can I get one that is
truly
> > extensible?

> Well, arrays in .NET (not only in MC++) are not really extensible, at
least
> for now, in this sense. As usual, one would use a wrapper class, which in
> this case would be ArrayList or one of the other collection classes in
> System::Collections.

Yes, I have reverted to ArrayList, which is not strongly typed (all members
are Object*) but I can deal with it.

Thanks,

Steve



Fri, 09 Jul 2004 06:38:43 GMT  
 Dynamic arrays not really dynamic in managec C++?
Hi Stephen,

Quote:
> Well the Managed Extensions Reference uses the term:  "A __gc array is a
> dynamic array that is allocated on the common language runtime heap."

I guess they are refering to the fact that the array is always dynamically
allocated (using new), and not statically allocated with a fixed size on the
stack, as it's common in C/C++.

Quote:
> But
> what really mislead me is that __gc arrays inherit from System::Array and
> actually do have methods like Add().
> It just so happens that the
> IsFixedSize property is always false (as far as I can tell, though I have
> not found that fact in the docs).

Funny that. It returns true here.

As for the presence of Array::Add() (or Array::IsFixedSize, for that
matter), it is there because the Array class implements the IList interface.

--
Tomas Restrepo



Fri, 09 Jul 2004 06:57:05 GMT  
 Dynamic arrays not really dynamic in managec C++?

Quote:
> > But
> > what really mislead me is that __gc arrays inherit from System::Array
and
> > actually do have methods like Add().

> > It just so happens that the
> > IsFixedSize property is always false (as far as I can tell, though I
have
> > not found that fact in the docs).

> Funny that. It returns true here.

Sorry, got confused.  I meant to say 'true'.  So that makes sense, just
disappointed since the MC++ docs did not warn me that that would always be
the case.

Thanks,

-Steve



Fri, 09 Jul 2004 07:54:55 GMT  
 Dynamic arrays not really dynamic in managec C++?
Hi Stephen,

Quote:
> Sorry, got confused.  I meant to say 'true'.  So that makes sense, just
> disappointed since the MC++ docs did not warn me that that would always be
> the case.

Well, the docs for Array::IsFixedSize do clearly state that arrays will
always return true, but I guess you have a point in that it should be
mentioned in the language spec, too.

--
Tomas Restrepo



Fri, 09 Jul 2004 08:01:51 GMT  
 Dynamic arrays not really dynamic in managec C++?
They are dynamic in the sense that you can do:

array = new Object*  [100];

on the next line. There is also a Copy method that lets you copy the
elements in a new instance that you can re-assign to the original reference.
What they are not is dynamically _sized_.

Ronald Laeremans
Visual C++ compiler team


Quote:
> E{*filter*}d by the promise of "dynamic arrays", I wrote a bunch of code like
> this::

> __gc class MyClass {
>     Object* array [];

>     MyClass() {
>         array = new Object* [0];
>     }

>     void MorePlease(Object* o) {
>         array->Add(o);       // throws exception:  Collection was of a
fixed
> size
>     }
> };

> Did I misunderstand what "dynamic" means?  How can I get one that is truly
> extensible?

> Thanks,

> Steve



Fri, 09 Jul 2004 12:24:27 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Can't free dynamic array (Visual C++ 6.0)

2. C/C++: Dynamic allocation of string array

3. dynamic multidimension arrays in c++

4. Can I Define a Dynamic Array in C++?

5. How to inspect dynamic array ( my_struct* array) ?

6. Control Arrays/Dynamic Arrays

7. Lists VS. Dynamic Arrays VS. Re-defining Arrays

8. Determining dynamic from non-dynamic memory

9. dynamic linked list + dynamic struct members

10. HELP -> dynamic array of char** in dynamic array of mystruct**

11. C# Dynamic Array?

12. Error/Bug in VC++ .Net, size of a Dynamic Array

 

 
Powered by phpBB® Forum Software