Click here to Skip to main content
15,913,487 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to implement "class factory" in C# Pin
Feng Qin27-Jun-02 18:33
Feng Qin27-Jun-02 18:33 
GeneralRe: How to implement "class factory" in C# Pin
James T. Johnson27-Jun-02 18:41
James T. Johnson27-Jun-02 18:41 
GeneralRe: How to implement "class factory" in C# Pin
Feng Qin27-Jun-02 19:06
Feng Qin27-Jun-02 19:06 
GeneralRe: How to implement "class factory" in C# Pin
James T. Johnson27-Jun-02 19:23
James T. Johnson27-Jun-02 19:23 
GeneralRe: How to implement "class factory" in C# Pin
Marc Clifton28-Jun-02 0:42
mvaMarc Clifton28-Jun-02 0:42 
GeneralRe: How to implement "class factory" in C# Pin
James T. Johnson28-Jun-02 11:07
James T. Johnson28-Jun-02 11:07 
GeneralRe: How to implement "class factory" in C# Pin
James T. Johnson28-Jun-02 11:43
James T. Johnson28-Jun-02 11:43 
GeneralRe: How to implement "class factory" in C# Pin
Marc Clifton30-Jun-02 5:30
mvaMarc Clifton30-Jun-02 5:30 
Very interesting. Notice though the actual assembly code generated:

00000000 push ebp ; save EBP
00000001 mov ebp,esp ; save ESP
00000003 push eax ; allocates 8 bytes on stack
00000004 push esi ; save ESI
00000005 mov esi,ecx ; get object reference
00000007 mov eax,dword ptr [esi+8] ; get count
0000000a pop esi ; restore ESI
0000000b mov esp,ebp ; restore ESP ***
0000000d pop ebp ; restore EBP
0000000e ret ; return

The value is returned in EAX. I added the comments. The line I designated with *** is interesting, in that it restores the ESP to the state prior to the push eax/push esi. In this code example, the 8 bytes allocated by push eax are actually never used, but forced into creation I suspect by the .maxstack directive.

The IDL (is that the right acronym) uses the stack after saving the ESP for local values (this is the way things are usually done), and then throws away all the local stuff at the end by "mov esp, ebp". In the above case, the optimizer figured out that the stack space allocated didn't need to be used--the return value could just be placed into the EAX register. Unfortunately, it still allocated the space, so a few cycles were wasted.

It would be interesting to see how a struct is returned. I remember looking at assembly code in the past, and something about a memcpy being called.

So, the IDL (I really hope this is the right acronym) abstracts the resulting assembly so you could port it to other processors. What bothers me about the above IDL is that it obscures the return value. There must be some assumptions about what is getting returned, since it clearly wasn't specified in the IDL code. Any ideas?

Marc



GeneralRe: How to implement "class factory" in C# Pin
Feng Qin30-Jun-02 18:41
Feng Qin30-Jun-02 18:41 
GeneralRe: How to implement "class factory" in C# Pin
Marc Clifton3-Jul-02 2:09
mvaMarc Clifton3-Jul-02 2:09 
GeneralConfiguration file for application Pin
tomiga26-Jun-02 22:17
tomiga26-Jun-02 22:17 
GeneralRe: Configuration file for application Pin
tomiga26-Jun-02 22:18
tomiga26-Jun-02 22:18 
GeneralRe: Configuration file for application Pin
James T. Johnson27-Jun-02 16:16
James T. Johnson27-Jun-02 16:16 
GeneralRe: Configuration file for application Pin
tomiga27-Jun-02 22:41
tomiga27-Jun-02 22:41 
GeneralResource problems... Pin
Ray Cassick26-Jun-02 18:10
Ray Cassick26-Jun-02 18:10 
GeneralRe: Resource problems... Pin
Ray Cassick26-Jun-02 19:09
Ray Cassick26-Jun-02 19:09 
QuestionNo .RC File??? Pin
Marc Clifton26-Jun-02 14:37
mvaMarc Clifton26-Jun-02 14:37 
AnswerRe: No .RC File??? Pin
Chris Rickard26-Jun-02 14:51
Chris Rickard26-Jun-02 14:51 
Questionstructs as value and classes as reference??? Pin
Marc Clifton26-Jun-02 14:15
mvaMarc Clifton26-Jun-02 14:15 
AnswerRe: structs as value and classes as reference??? Pin
Chris Rickard26-Jun-02 14:52
Chris Rickard26-Jun-02 14:52 
AnswerRe: structs as value and classes as reference??? Pin
Feng Qin26-Jun-02 16:31
Feng Qin26-Jun-02 16:31 
GeneralRe: structs as value and classes as reference??? Pin
Marc Clifton27-Jun-02 0:36
mvaMarc Clifton27-Jun-02 0:36 
GeneralRe: structs as value and classes as reference??? Pin
SimonS27-Jun-02 2:27
SimonS27-Jun-02 2:27 
GeneralRe: structs as value and classes as reference??? Pin
Andy Smith27-Jun-02 11:17
Andy Smith27-Jun-02 11:17 
GeneralRe: structs as value and classes as reference??? Pin
Feng Qin27-Jun-02 18:38
Feng Qin27-Jun-02 18:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.