472,983 Members | 2,928 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Generic Type Instantiation Again

From <http://msdn2.microsoft.com/en-us/library/f4a6ta2h(en-US,VS.80).aspx>:

| As with the previous use of the Stack<T> class created with the Order
| type, another instance of the specialized Stack<T> class is created,
| and the pointers contained therein are set to reference an area of
| memory the size of a Customer type.

I don't quite get this. Where in memory do these changes (the pointers
getting set) take place?
Dec 7 '05 #1
8 1592
Cool Guy,

This is handled by the CLR. The CLR will create a separate type
definition for every distinct combination of value types used in a generic
type as type parameters. So, if you have Stack<int> and Stack<byte>, the
CLR will actually create two type definitions.

If you have a Stack<Customer> and Stack<Order> where Customer and Order
are reference types, then the CLR creates one type definition to use between
the two of them. The reason for this is that you are not dealing with the
actual memory that instances of the type take up, but rather, references,
which are all one, constant size.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Cool Guy" <co*****@abc.xyz> wrote in message
news:1r***************@cool.guy.abc.xyz...
From
<http://msdn2.microsoft.com/en-us/library/f4a6ta2h(en-US,VS.80).aspx>:

| As with the previous use of the Stack<T> class created with the Order
| type, another instance of the specialized Stack<T> class is created,
| and the pointers contained therein are set to reference an area of
| memory the size of a Customer type.

I don't quite get this. Where in memory do these changes (the pointers
getting set) take place?

Dec 7 '05 #2
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote:
This is handled by the CLR. The CLR will create a separate type
definition for every distinct combination of value types used in a generic
type as type parameters. So, if you have Stack<int> and Stack<byte>, the
CLR will actually create two type definitions.

If you have a Stack<Customer> and Stack<Order> where Customer and Order
are reference types, then the CLR creates one type definition to use between
the two of them. The reason for this is that you are not dealing with the
actual memory that instances of the type take up, but rather, references,
which are all one, constant size.


That much, I understand, but the part of the article I quoted in the OP
threw me. I'm trying to figure out precisely which pointers are set*, in
order to understand what goes on under the hood.

* The quote was: "[...] the pointers contained therein are set to reference
an area of memory the size of a Customer type."
Dec 7 '05 #3
Cool Guy,

Basically, the references are references to type Customer. However,
from the generic type's point of view, this doesn't matter. The only thing
the generic type cares about, if it is a reference type, is the fact that
because it is a reference type, the size requirements for fields and whatnot
are the same.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Cool Guy" <co*****@abc.xyz> wrote in message
news:db***************@cool.guy.abc.xyz...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote:
This is handled by the CLR. The CLR will create a separate type
definition for every distinct combination of value types used in a
generic
type as type parameters. So, if you have Stack<int> and Stack<byte>, the
CLR will actually create two type definitions.

If you have a Stack<Customer> and Stack<Order> where Customer and
Order
are reference types, then the CLR creates one type definition to use
between
the two of them. The reason for this is that you are not dealing with
the
actual memory that instances of the type take up, but rather, references,
which are all one, constant size.


That much, I understand, but the part of the article I quoted in the OP
threw me. I'm trying to figure out precisely which pointers are set*, in
order to understand what goes on under the hood.

* The quote was: "[...] the pointers contained therein are set to
reference
an area of memory the size of a Customer type."

Dec 7 '05 #4
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote:
Basically, the references are references to type Customer. However,
from the generic type's point of view, this doesn't matter. The only thing
the generic type cares about, if it is a reference type, is the fact that
because it is a reference type, the size requirements for fields and whatnot
are the same.


Yep, I understand that. :) I'm trying to work out precisely which
pointers are being spoken about in the following:

| [...]
| and the pointers contained therein are set to reference an area of
| memory the size of a Customer type.

The pointers contained in what?
Dec 7 '05 #5
I wrote:

[snip]

Just to clarify -- I realise that it's not essential to know this in
general; I'm simply asking so that I can work what goes on under the hood
in this situation.
Dec 7 '05 #6
I wrote:

[snip]

This is the kind of thing I'm talking about -- from
<http://www.artima.com/intv/generics2.html>:

| Anders Hejlsberg: [...] For all reference types
| we share the code, because they are representationally
| identical. It's just pointers.
|
| Bruce Eckel: And you just need to cast.
|
| Anders Hejlsberg: No, you don't actually. We can
| share the native image, but they actually have
| separate VTables. [...]

Now, *this* makes sense, but what I don't understand is where the

"the pointers contained therein are set to reference an area of memory
the size of a Customer type"

thing fits it. Any ideas?
Dec 7 '05 #7
>Now, *this* makes sense, but what I don't understand is where the

"the pointers contained therein are set to reference an area of memory
the size of a Customer type"

thing fits it. Any ideas?


It sounds plain wrong (or just poorly worded) to me. This part is more
like a description of what happens when you create an instance of the
type parameter T. That doesn't happen when the Stack type is created.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 7 '05 #8
Mattias Sjögren <ma********************@mvps.org> wrote:
Now, *this* makes sense, but what I don't understand is where the

"the pointers contained therein are set to reference an area of memory
the size of a Customer type"

thing fits it. Any ideas?


It sounds plain wrong (or just poorly worded) to me. This part is more
like a description of what happens when you create an instance of the
type parameter T. That doesn't happen when the Stack type is created.


Thanks!
Dec 8 '05 #9

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

Similar topics

6
by: Joanna Carter \(TeamB\) | last post by:
I want to be able to use a generic type, bind its generic parameters to specific type(s) and then hold newly created instances in a list of generic ypes. Sort of like this : class Agent<T> {...
4
by: Cool Guy | last post by:
I don't understand the third paragraph under the heading 'Generic type instantiations' on <http://msdn.microsoft.com/vcsharp/2005/overview/language/generics/>: | The .NET Common Language Runtime...
6
by: Dan Holmes | last post by:
I have a class that i need a constraint of int, string, float or bool. I have tried the following but can't make VS accept it. I read the docs and they showed that any value type can be used...
3
by: Boris | last post by:
I have a class which should like this ideally: generic <typename T> public ref class ManagedClass { T ^managedMember; UnmanagedClass<U*unmanagedMember; }; I actually would like to specify...
7
by: Dave | last post by:
I've got these declarations: public delegate void FormDisplayResultsDelegate<Type>(Type displayResultsValue); public FormDisplayResultsDelegate<stringdisplayMsgDelegate; instantiation:...
3
by: Peter K | last post by:
Hi I have an interface for a "factory" defined like this: public interface IDeviceFactory<T: IDisposable { T GetDevice(); }
11
by: paul.gibson | last post by:
A simple code example is easier than trying to describe the issue. I have: public class myClassA {
11
by: Scott Stark | last post by:
Hello, The code below represents a singly-linked list that accepts any type of object. You can see I'm represting the Data variable a System.Object. How would I update this code to use...
8
by: Advait Mohan Raut | last post by:
Hello, I am using VC# 2005 ; C# 2.0 I am working on the performance measurement tool. For that I need my code to call user defined method along with its parameters. For that should I use a...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.