Results 1 to 4 of 4

Thread: General Question

Hybrid View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    General Question

    Hopefully this is not outside the forum scope.

    Getting information on how the VB compiler handles various things would be helpful to know whether it is more efficient to code in a certain way. For example a question of late is:

    QUESTION
    How the compiler handles string memory storage.

    I can see three possible alternatives.

    1) The compiler stores all strings in a central memory location and just has a pointer reference stored on either the heap or stack.

    2) The compiler uses where the string is declared to determine where the string is placed in memory.

    In the simplest case if the string is declared locally (Dim strPrompt As String) and then assigned in the local procedure to the local variable, the entire string logically would be put in stack memory.

    3) The compiler uses the variable to which the string is assigned to determine where it is stored (heap or stack). In this case, if no local variable is declared, and the string is assigned to a global variable, does the compiler consider the string to belong to the local procedure or does the assignment "rule" ?

    If the assignment does Not rule, then the string logically would belong to the local procedure and the assignment to the global variable would cause either a copy of the string to also be stored on the heap (per your above) or pointer reference copied to the heap?

  2. #2
    Special Guest - Microsoft
    Join Date
    Dec 2007
    Posts
    3

    Re: General Question

    Are you talking about strings used by an application written in VB.NET?

    In .NET, strings are represented by System.String object, which is a reference type and is stored on the heap. Whenever compiler runs into a string literal, it emits code that allocates new System.String object and stores the reference to the object in the target variable, field, etc.

    Thanks,
    Aleksey Tsingauz,
    VB.NET Compiler Dev Team.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    Re: General Question

    Alex:

    From my read of your post, your saying System.String object stores all string literals on the heap no matter whether they are declared Public, Private or Local.

    Is this correct, or are you saying the System.String object is stored on the heap?

  4. #4
    Special Guest - Microsoft
    Join Date
    Dec 2007
    Posts
    3

    Re: General Question

    Quote Originally Posted by dw85745
    Alex:

    From my read of your post, your saying System.String object stores all string literals on the heap no matter whether they are declared Public, Private or Local.

    Is this correct, or are you saying the System.String object is stored on the heap?
    System.String objects and strings associated with them are stored on the heap, this is how CLR works.

    Thanks,
    Aleksey Tsingauz,
    VB.NET Compiler Dev Team.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width