473,799 Members | 3,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1202
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*******@Roun dTripInc.com> wrote in message
news:uK******** *****@TK2MSFTNG P14.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<Fo o>), 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*******@Roun dTripInc.com> wrote in message
news:uK******** *****@TK2MSFTNG P14.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<Fo o>), 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<MyC lass *> * pMyArray = new std::vector<MyC lass *>(100);

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

std::vector<MyC lass *> 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<MyC lass *> * pMyArray = new std::vector<MyC lass *>(100);

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

std::vector<MyC lass *> 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<M yClass *> * pMyArray = new std::vector<MyC lass *>(100);

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

std::vector<M yClass *> 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<MyCla ss ^> 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
2812
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
2382
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 ArrayEntryType(1), new ArrayEntryType(2)}; public static ArrayEntryType array2 = {
3
4162
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; unsigned char cBuf __gc = new unsigned char __gc; .... strncpy(cBuf, (cResult + 10), 5); ***********************************************
16
2632
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 control.... *Help* is pretty important. The help feature topics are very badly organized. There is ambiguity and context disorder. The topic headings are misleading and a lot is assumed about the knowledge of the user. Example, *managed code" is...
11
1714
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 a lot of converting '__gc' to 'ref', converting '*' to '^', converting 'new' to 'gcnew'. Of course this can't be done with a blanket replace, as my code has both managed and unmanaged segments. Thus I have to do them one-by-one. Also, things are...
3
1131
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 it like this : Let's say I have one object called "Compact_Disk" and a second object called "Song". A compact disk can contain any number of songs. In .NET v1, I could define my song array in my .h file as : Song* diskSongs __gc;
0
942
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 array of string arrays, and contains some nullptr items, sample code below. Looking at the IL using .Net Reflector also below I think I see why. This issue is easy to work around by using a gcnew array<String^{} instead of a nullptr, but is not...
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.