Re: C++ vs. C#
On Dec 31, 5:28 am, tonytech08 <tonytec...@gmail.com> wrote:
On Dec 30, 8:01 pm, SG <s.gesem...@gmail.com> wrote:
I didn't find any definition of "lightweight". But the way
this word is used suggests that Microsoft likes to call
value types "lightweight":
"The struct type is suitable for representing lightweight objects
such as Point, Rectangle, and Color. Although it is possible to
represent a point as a class, a struct is more efficient in some
scenarios. For example, if you declare an array of 1000 Point
objects, you will allocate additional memory for referencing each
object. In this case, the struct is less expensive."
"In C#, a struct is like a lightweight class; it is a stack-
allocated type that can implement interfaces but does not support
inheritance."
Yeah, you're on the correct pages on the MS site. That's what
I was reading a few days ago also. Again, the documentation is
just AKIN to what I was alluding to as being relevant and
important going forward. (I'm not gonna spoon feed anyone).
You mean that you're not going to let anyone know what you mean.
In case you havn't noticed in C++ neither structs nor
classes define types that behave like references and thus
would qualify as being lightweight.
You're free to make your own definition of "lightweight" if
you choose to. The above that you wrote does not match mine.
So what is yours. You refuse to tell us (or you're incapable of
telling us).
Also, then do a search within that documentation for facilities that
give the developer strict control over the layout of fields within
structs/lightweight classes.
Can you provide more specific pointers?
Probably... hang on... Here's a good jumping off point:http://msdn.micro=
soft.com/en-us/library/aa288471(VS.71).aspx. It's the
tutorial on C# structs. Note the "StructLayoutAttribute Class" under
"Further Reading". I'm not promoting that as a suggested
implementation, but rather pointing out that layout control is
important sometimes and that C# recognizes (and is able to "exploit"
it) that also.
C# allows explicit user defined layout. I'm not sure what the
consequences are, however (except when used to simulate a
union---and it's a very awkward way of simulating a union). The
results certainly can't be portable; I suspect that the intent
is only to be able to force compatibility with some legacy
interface on a specific system.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34