Java的ThreadLocal如何实现?(How is Java's ThreadLocal implemented under the hood?)
ThreadLocal如何实现? 它是否在Java中实现(使用从ThreadID到对象的一些并发映射),还是使用一些JVM钩来更有效地执行它?
How is ThreadLocal implemented? Is it implemented in Java (using some concurrent map from ThreadID to object), or does it use some JVM hook to do it more efficiently?
原文:https://stackoverflow.com/questions/1202444
最满意答案
是。 这是由C#规范保证的。 在7.18节(C#3.0规范)中:
每当表达式满足上述要求时,表达式将在编译时进行评估。 即使表达式是包含非常量结构的较大表达式的子表达式,也是如此。
(“上述要求”,包括+运算符应用于两个常数表达式。)
另见这个问题 。
Yes. This is guaranteed by the C# specification. It's in section 7.18 (of the C# 3.0 spec):
Whenever an expression fulfills the requirements listed above, the expression is evaluated at compile-time. This is true even if the expression is a sub-expression of a larger expression that contains non-constant constructs.
(The "requirements listed above" include the + operator applied to two constant expressions.)
See also this question.
相关问答
更多-
控制字符: (十六进制代码采用与ASCII兼容的字符编码。) \a = \x07 =警报(钟) \b = \x08 = backspace \t = \x09 =水平标签 \n = \x0A =换行符(或换行符) \v = \x0B =垂直标签 \f = \x0C =换页 \r = \x0D =回车 \e = \x1B =转义(非标准GCC扩展) 标点符号: \" =引号( '"'不需要反斜杠) \' =撇号( "'"不需要反斜杠) \? =问号(用于避免三字母) \\ =反斜杠 数字字符引用: \ +最多 ...
-
是。 这是由C#规范保证的。 在7.18节(C#3.0规范)中: 每当表达式满足上述要求时,表达式将在编译时进行评估。 即使表达式是包含非常量结构的较大表达式的子表达式,也是如此。 (“上述要求”,包括+运算符应用于两个常数表达式。) 另见这个问题 。 Yes. This is guaranteed by the C# specification. It's in section 7.18 (of the C# 3.0 spec): Whenever an expression fulfills the r ...
-
在C#中优化字符串比较(Optimize string comparison in C#)[2023-05-21]
HashSet是包含以下内容的最佳容器: var ips = new HashSet { "ip1", "ip2", "ip3", "ip4", "ip5" }; if (ips.Contains(input)) { // do stuff } 对于任何类型: var ips = new HashSet { ip1, ip2, ip3, ip4, ip5 }; if (ips.Contains(input)) { // do stuff } ... -
我拿了你的代码并在一个简单的控制台应用程序中编译它。 然后,我检查了IL(使用ILSpy)。 在调试或释放模式下都没有进行优化。 在这种情况下,代码可能很简单,编译器没有进行任何优化。 但是,更复杂的版本可能会产生不同的结果。 另请注意,这两个示例之间的差异很小。 在这两种情况下,运行时最终会生成四个不同的字符串对象。 在第一个示例中,对变量的赋值仅执行两次,而在第二个示例中,赋值执行三次。 但是,无论如何都会创建四个字符串。 它们如下: “ABCDEFGHIJKLMNOPQRSTUVWXYZ” “abcd ...
-
您可以使用C#中的SqlConnectionStringBuilder类创建动态连接字符串,如下所示。 有关详细信息,请访问http://msdn.microsoft.com/en-us/library/dce36088.aspx private void Form1_Load(object sender, EventArgs e) { SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder(); ...
-
使用C#进行字符串连接(String concatenation using C#)[2022-01-29]
拆分和修剪 // include linq library like this: // using System.Linq; // then "test1, test2".Split(',').Select(o => o.Trim()); 要么 "test1, test2".Split(',').Select(o => o.Trim()).ToArray(); // returns array 和 "test1, test2".Split(',').Select(o => "\"" + o.Tr ... -
p2来自同一条款: 字符串文字是用双引号括起来的零个或多个多字节字符的序列,如"xyz" 。 再次阅读报价,强调我的: 在转换阶段6中,由任何相邻字符序列和相同前缀字符串文字标记指定的多字节字符序列被连接成单个多字节字符序列。 您可以连接相邻的字符串文字标记和相同前缀的字符串文字标记。 (为避免任何疑问,C中没有“字符文字”; 'c'是字符常量 ,参见§6.4.4.4。) p2 from the same subclause: A character string literal is a sequence ...
-
如果您创建新字符串,它们将不会自动放入实习池,除非您连接常量编译时,在这种情况下,编译器将创建一个字符串结果和作为JIT过程的一部分的实习生。 If you create new strings, they will not automatically be put into the intern pool, unless you concatenate constants compile-time, in which case the compiler will create one string res ...
-
StandardAnalyzer过滤掉停用词,例如“it”。 但是当你搜索时,你会将“it”当作关键字。 您可以使用带有停用词列表的StandardAnalyzer构造函数 ,并使用空集来调用它。 The StandardAnalyzer filters out the stop words, such as "it". But when you are searching you include the "it" as a keyword. You could use the StandardAnalyz ...
-
C#串联字符串(C# String literal with concatenation)[2022-12-23]
将@放在第二个字符串前或使用String.Format() Put the @ in front of the second string literal or use String.Format()