473,398 Members | 2,427 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,398 software developers and data experts.

VS.NET 2005 'array' seems more complex to me than '__gc[]'

While it does look like 2005 does use a better syntax in general for garbage
collection than 2003, here is something I think went the other way. arrays.
Do people really think that:

array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(100);

is a better syntax than:

MyClass* MyArray __gc [] = new MyClass* __gc [100] ;

[==P==]
Nov 17 '05 #1
8 1188
My preference is to keep "__gc". I think it makes things more clear.
While it does look like 2005 does use a better syntax in general for
garbage collection than 2003, here is something I think went the other
way. arrays. Do people really think that:

array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(100);

is a better syntax than:

MyClass* MyArray __gc [] = new MyClass* __gc [100] ;

[==P==]


--
new
Nov 17 '05 #2
Yes, I do. (and strongly).

Brian

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:uK*************@TK2MSFTNGP14.phx.gbl...
While it does look like 2005 does use a better syntax in general for
garbage collection than 2003, here is something I think went the other
way. arrays. Do people really think that:

array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(100);

is a better syntax than:

MyClass* MyArray __gc [] = new MyClass* __gc [100] ;

[==P==]

Nov 17 '05 #3

Peter Oliphant a écrit :
While it does look like 2005 does use a better syntax in general for garbage
collection than 2003, here is something I think went the other way. arrays.
Do people really think that:

array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(100);

is a better syntax than:

MyClass* MyArray __gc [] = new MyClass* __gc [100] ;


If you're used to native STL (std::vector<Foo>), it certainly looks
clearer IMHO.

Arnaud
MVP - VC

Nov 17 '05 #4
Depends on whether you've used templates previously.

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:uK*************@TK2MSFTNGP14.phx.gbl...
While it does look like 2005 does use a better syntax in general for
garbage collection than 2003, here is something I think went the other
way. arrays. Do people really think that:

array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(100);

is a better syntax than:

MyClass* MyArray __gc [] = new MyClass* __gc [100] ;

[==P==]

Nov 17 '05 #5
ad******@club-internet.fr wrote:
Peter Oliphant a écrit :

While it does look like 2005 does use a better syntax in general for garbage
collection than 2003, here is something I think went the other way. arrays.
Do people really think that:

array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(100);

is a better syntax than:

MyClass* MyArray __gc [] = new MyClass* __gc [100] ;

If you're used to native STL (std::vector<Foo>), it certainly looks
clearer IMHO.

Arnaud
MVP - VC


Arnaud:

I am only just starting to look at managed code (don't have the VC8
compiler yet!), but that is what I thought too. The old form does not
look like legal standard C++, but the new one is like

std::vector<MyClass *> * pMyArray = new std::vector<MyClass *>(100);

This is legal standard C++, though not what I would use (never use new
unless you have to). I would do

std::vector<MyClass *> myArray(100);

Now I read that C++/CLI has optional "stack semantics". So can I do

array<MyClass ^> myArray(100);

? Or is this not allowed? If not, why not?

David Wilkinson

Nov 17 '05 #6
You said "never use new unless you have to".

You and I share the same feelings about coding style.

I, too, am new to MC++ and I can tell you that I both like it and
despise it.

It seems that MC++ turns our kind of coding on its head and everything
ends up on the heap. Destructors don't get executed when you want them
to under MC++. (Maybe I'm missing something.)

Anyway, I've only got MC++ 2003. Does the stack semantics apply to
that version?

Nov 17 '05 #7
David Wilkinson wrote:

I am only just starting to look at managed code (don't have the VC8
compiler yet!), but that is what I thought too. The old form does not
look like legal standard C++, but the new one is like

std::vector<MyClass *> * pMyArray = new std::vector<MyClass *>(100);

This is legal standard C++, though not what I would use (never use new
unless you have to). I would do

std::vector<MyClass *> myArray(100); I definitely agree with you in native C++ (I almost never write a "new"
anymore in native code). Anyway, in the managed world, newing an object is
the only way to create it and register it with the GC (btw, this is the same
thing in Java). Now, as MC++ and C++/CLI are designed to be closer to the
metal than C# or VB, the syntax is a bit clumsy.

Now I read that C++/CLI has optional "stack semantics". So can I do

array<MyClass ^> myArray(100);

? Or is this not allowed? If not, why not?


It is not, and I don't know why :-( It seems that stack semantic is not
available for arrays...
Anyway, this is not really necessary here : The main goal of stack semantic
is not to ease syntax, it is to provide RAII. RAII has a meaning only if
there is some ressource to free, but an array does not hold any such
ressource (except memory of course, which is taken care of by the GC).

Arnaud
MVP - VC
Nov 17 '05 #8
Arnaud Debaene wrote:
David Wilkinson wrote:
I am only just starting to look at managed code (don't have the VC8
compiler yet!), but that is what I thought too. The old form does not
look like legal standard C++, but the new one is like

std::vector<MyClass *> * pMyArray = new std::vector<MyClass *>(100);

This is legal standard C++, though not what I would use (never use new
unless you have to). I would do

std::vector<MyClass *> myArray(100);


I definitely agree with you in native C++ (I almost never write a "new"
anymore in native code). Anyway, in the managed world, newing an object is
the only way to create it and register it with the GC (btw, this is the same
thing in Java). Now, as MC++ and C++/CLI are designed to be closer to the
metal than C# or VB, the syntax is a bit clumsy.

Now I read that C++/CLI has optional "stack semantics". So can I do

array<MyClass ^> myArray(100);

? Or is this not allowed? If not, why not?

It is not, and I don't know why :-( It seems that stack semantic is not
available for arrays...
Anyway, this is not really necessary here : The main goal of stack semantic
is not to ease syntax, it is to provide RAII. RAII has a meaning only if
there is some ressource to free, but an array does not hold any such
ressource (except memory of course, which is taken care of by the GC).

Arnaud
MVP - VC


Hi Arnaud:

Yes I understand that the reference class is really always allocated on
the GC heap (though Herb Sutter has said that even that could be relaxed
in future versions in some circumstances), and that the stack semantics
is intended for use with RAII. And a great improvement that is!!

But once stack semantics has been introduced, I fail to see why it might
not be universally used. Surely a handle and a "reference to a handle"
must be interchangeable as far as the compiler is concerned (except that
the latter triggers a destructor call when it goes out of scope). Isn't
it just like the relationship between bare pointer and auto-ptr?. For
non-RAII classes, the presence of an empty destructor cannot be any more
of a problem than it is in standard C++.

David Wilkinson

Nov 17 '05 #9

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

Similar topics

0
by: Olav Langeland | last post by:
I have a C# Form with a System.Windows.Forms.PropertyGrid(). This uses a Datagram class, implemented in both C# and C++: // C# public class Datagram { public byte _Buffer; // some code...
2
by: Roy Chastain | last post by:
I have a C# module that defines a type and then makes several arrays of that type. public class ArrayEntryType { byte member1; .... ]; public static ArrayEntryType array1 = { new...
3
by: Steve | last post by:
How can I copy 5 bytes from the middle of one array to another in Managed C++? The following code segment causes the compilation errors below: unsigned char cResult __gc = new unsigned char __gc;...
16
by: John Gabriel | last post by:
The *back* and *forward* butttons do not work. Anyone noticed this? I know this is a beta edition but even for a beta edition, it's hard to believe Microsoft performed any real quality...
11
by: Peter Oliphant | last post by:
I've been trying all morning to convert my 2003 project (managed) to 2005 (/clr since I have both managed and unmanaged code). I'm guessing I have tens of thousands of lines of code to change. Did...
3
by: Mark Prenter | last post by:
Hi, I'm having a heck of a time figuring out arrays in the new version of ..NET. I'm used to .NET version 1. I'm trying to set the size of an array, when an object is created.....let me explain...
0
by: craig.conboy | last post by:
Using MC++ .Net 2.0, with the CLR Profiler (from Microsoft) I am seeing that 3 blocks of memory, each ~48MB in size, being allocated by some code that initializes a managed array. It is a jagged...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.