什么时候(不)两个字符串相同的内容共享相同的内存? [英] When do (not) two strings with same content share the same memory?

查看:84
本文介绍了什么时候(不)两个字符串相同的内容共享相同的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题的<一即将href="http://stackoverflow.com/questions/15805578/will-two-strings-with-same-content-be-stored-in-the-same-memory-location">will两个字符串与相同的内容被存储在同一存储器地址?的

拥有了Java code

Having the Java code

String s1="Java";

将这个字符串被分配在相同的存储器位置(或多发性):

will this string be allocated in the same memory location (or multipe):

  • 如果启动并行(兼)执行它同一程序多次?

我目前的C#开发者(尽管在previous千年编程的Java)。

I am currently C# developer (though programmed in Java in the previous millennium).

我问这个问题,因为我认为这是.NET CLR和Java(JVM)之间的相同,我希望得到的.NET应用程序的答案(但不知何故被怀疑通过经常遇到的应用程序池术语) 。

I asked this question because I believed it is the same between .NET CLR and Java (JVM) and I was hoping to get the answer for .NET apps (but somehow was in doubt by frequently encountered "application" pool terms).

因此​​,它似乎是(对不起,问之前没有彻底搜索):

So, it seems to be (sorry for not exhaustively searching before asking):

  • <一个href="http://stackoverflow.com/questions/6568905/does-the-clr-jvm-keep-one-single-intern-pool-for-all-running-net-java-apps">Does在CLR / JVM保持一个单一的实习生池的所有正在运行的.NET / Java应用程序?

字符串实习生池占所有实例共享的接听/同一个JVM或.NET CLR的程序。

with the answer that string intern pool is shared per all instances/programs of the same JVM or .NET CLR.

推荐答案

@根纳季 - 瓦宁 - 新西伯利亚......

@gennady-vanin-novosibirsk....

字符串S1 =Java的;串S =Java的;串S =Java的;字符串S4 =Java的;

String s1="Java";String s2="Java";String s3="Java";String s4="Java";

  1. 上面可用的所有对象的 StringConstantPool 的位置,那些所有对象都指向只有一个(Java的)位置
  1. The above all objects available in StringConstantPool location those are all objects are pointing to only one ("Java") location

这篇关于什么时候(不)两个字符串相同的内容共享相同的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆