none
Some basic questions on .NET RRS feed

  • Question

  • Stack
    When I create a int value;

    For example, int i = 99;

    Does the value 99 gets pushed into the stack and gets poped out when it is needed to be used or when it is no longer needed (eg:end of method)?


    Garbage Collection
    Does the garbage collector have a 3-tier architecture? Or does 3-tier architecture refer to the Domain/Controller/UI?


    Threading
    How can I call create a thread to accept a method which has parameters? Of course, if it doesnt have parameters, it'll can be done.

    for example, this method :
    (Thread this method !)

    public void SaySomething(string s){ Console.Out.WriteLine(s); }


    Structs
    My understanding for structs ... (help correct me if i'm wrong)
    Structs are designed to be a alternative for classes if it mostly contains values. Because structures are placed on the stack, they requires lesser overhead compared to managing objects on the heap, Why? Does the overhead refering to checking which object does a reference is pointing to?

    The reason why it doesnt have a constructor is because it is a value type and all value types are initialized to it's default values if it doesn't get assigned to a value. (e.g. int,float,double,short,byte to 0, bool to false). Therefore if it does not get initialized, the default constructor should be called automatically and all values inside the structure are initialized to their default value.

    What happens if there is an object declared inside a structure? Then wouldn't it be stored on the heap? Wouldn't that defeat the purpose of structures then? Therefore it is value-semantic?




    Thank you ..



    • Moved by SJWhiteley Wednesday, September 3, 2008 3:38 PM Not a VB Specific question: moved to CLR (Moved from Visual Basic General to Common Language Runtime)
    Wednesday, September 3, 2008 2:05 PM

Answers

  • Stack:
    The variable is poped of the stack when the method ends.

    As far as I know the garbage collector is not a 3 tier architecture. 3 Tier architectre doens't even mean a Domain / controller/UI. 

    n Tier architecture is a design in which the code is separated into n components (a component or a tier is a sets of classes, project, executable, etc) where every component knows only the public methods of the uncerlying component. calls pass from higher tiers to lower ones, and every tier is allowed to call only public methods in the tier under it directly.
    The most famous example for this design is a UI tier that calls methods in a business logic tier which calls methods in a data access layer tier which deals with the database tier. 

    .NET Garbage collection uses a famous algorithm called generational garbage collection. Search for it and you will find it explained in many sites on the internet.

    Threading
    You can only pass one parameter which is an object. This object could be an instance of a  class which holds the data you want to pass instead of using multiple parameters. See this page for an example.

    http://muhammadadel.wordpress.com
    • Marked as answer by Zhi-Xin Ye Monday, September 8, 2008 7:16 AM
    Wednesday, September 3, 2008 5:19 PM

All replies

  • With regards to structures :

    Taken from (http://www.developer.com/net/asp/article.php/1756291),

    Structure—In .NET languages, structures are light-weight classes that are simpler, have less overhead, and are less demanding on the CLR. Structures are typically used for creating user-defined types that contain only public fields and no properties (identical to structures in the C language). But .NET structures, like classes, also support properties, access modifiers, constructors, methods, operators, nested types, and indexers. Unlike classes, however, structures do not support inheritance, custom constructors, a destructor (or Finalize) method, and no compile-time initialization of instance fields. It is important to note that a structure is a value type, while classes are a reference type. Performance will suffer when using structures in a situation where references are expected (e.g., in collections) and the structure must be boxed and unboxed for it to be used.

    Why must it be boxed and unboxed to be used? The reference type within the structure lives on the stack, thus there should be a pointer to that reference, as the pointer (value types) must point to a reference type, therefore the reference type living on the stack must be boxed to the heap? However, i thought all reference types MUST live on the heap?

    Please enlighten me... Thanks.

    Wednesday, September 3, 2008 2:45 PM
  • Stack:
    The variable is poped of the stack when the method ends.

    As far as I know the garbage collector is not a 3 tier architecture. 3 Tier architectre doens't even mean a Domain / controller/UI. 

    n Tier architecture is a design in which the code is separated into n components (a component or a tier is a sets of classes, project, executable, etc) where every component knows only the public methods of the uncerlying component. calls pass from higher tiers to lower ones, and every tier is allowed to call only public methods in the tier under it directly.
    The most famous example for this design is a UI tier that calls methods in a business logic tier which calls methods in a data access layer tier which deals with the database tier. 

    .NET Garbage collection uses a famous algorithm called generational garbage collection. Search for it and you will find it explained in many sites on the internet.

    Threading
    You can only pass one parameter which is an object. This object could be an instance of a  class which holds the data you want to pass instead of using multiple parameters. See this page for an example.

    http://muhammadadel.wordpress.com
    • Marked as answer by Zhi-Xin Ye Monday, September 8, 2008 7:16 AM
    Wednesday, September 3, 2008 5:19 PM