Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

关于java 代码的思考

for (String string : LinkList) {
    String RegisteredFund = null;
    String FounderName = null;
    List<String> AssociatedCompany = new ArrayList<String>();
    Map<String, String> TotalData = new HashMap<String, String>();

最近自己写代码发现java 一段代码,这代码每次从开始循环都要申请内存空间,感觉效率有点低,能不能在一开始申请一块内存,然后 循环结束给这个内存块清0,然后到循环开始的时候还是在这片区域赋值呢?感觉这样相当于缓存一个block 这样就会速度提高很多。

麻烦对java 内存申请熟悉的指教一下,谢谢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

放外面并不会在性能上有什么飞跃,反而会有线程安全的问题


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...