> In C#, for example, the code > System.Console.WriteLine("Hello World"); > > Does this create a System.String object, with own copy of "Hello World" in > Unicode encoding, in the run-time heap? > Does the run-time access the #US stream (user-defined string heap) to look > for the particular string and make a copy of that user-defined string into > the System.String object?
I think the answer is yes. The IL for that program looks like this: .method public hidebysig static void Main(string[] args) cil managed { .entrypoint .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) // Code size 11 (0xb) .maxstack 1 IL_0000: ldstr "Hello World!" IL_0005: call void [mscorlib]System.Console::WriteLine(string) IL_000a: ret } // end of method EntryPoint::Main I found a brief explanation of the 'ldstr' opcode here: http://longhorn.msdn.microsoft.com/lhsdk/ref/ns/system.reflection.emit/c /opcodes/f/ldstr.aspx "The ldstr instruction pushes an object reference (type O) to a new string object representing the specific string literal stored in the metadata. The ldstr instruction allocates the requisite amount of memory and performs any format conversion required to convert the string literal from the form used in the file to the string format required at runtime." > #2 > "System.String objects are created on demand for strings > literals." > In the built-in profiler in the Rotor, for example, when we display the > being-JITed-method's name onto the screen/log, will this create a > System.String object in the heap (to satisfy our request)? Or, will the > run-time simply access the #Strings (string heap) and display the > corresponding string literal? I'd say it will create the string in the heap. If you read the reference above you will note that a process known as 'string interning' is used to make sure that only one instance is referenced in the heap. John. =================================== This list is hosted by DevelopMentorŪ http://www.develop.com NEW! ASP.NET courses you may be interested in: 2 Days of ASP.NET, 29 Sept 2003, in Redmond http://www.develop.com/courses/2daspdotnet Guerrilla ASP.NET, 13 Oct 2003, in Boston http://www.develop.com/courses/gaspdotnet View archives and manage your subscription(s) at http://discuss.develop.com