首页 \ 问答 \ 非运行时分配解决方案 - ArrayList(Non runtime allocation solution - ArrayList)

非运行时分配解决方案 - ArrayList(Non runtime allocation solution - ArrayList)

我正在用Java进行游戏。 我需要一些针对当前运行时分配的解决方案,这是由我的ArrayList引起的。 垃圾收集器每分钟或30秒开始运行,因为我正在调用通过此集合的绘制和更新方法。

我应该如何做一个非运行时分配解决方案?

在此先感谢,如果需要,我的代码从我的Manager类中公布,其中包含对象的ArrayList

一些代码:

@Override
public void draw(GL10 gl) {
  final int size = objects.size();
  for(int x = 0; x < size; x++) {
    Object object = objects.get(x);
    object.draw(gl);
  }
}

public void add(Object parent) {
  objects.add(parent);
}

     //Get collection, and later we call the draw function from these objects
public ArrayList<Object> getObjects() {
   return objects;
}

public int getNumberOfObjects() {
   return objects.size();
}

更多解释:我与这种混合的原因是(1)我看到ArrayList实现很慢并导致滞后,(2)我想将对象/组件合并在一起。 当从我的Thread-class发起更新调用时,它会通过我的集合,使用Manager的更新函数将事物向下发送到树/图上。

查看Replica Island的开源项目时,我发现他使用了他自己编写的替代类FixedSizeArray。 由于我对Java不太擅长,我想让事情变得更简单,现在我正在寻找另一种解决方案。 最后,他解释了为什么他做了这个特殊班级:

FixedSizeArray是像ArrayList这样的标准Java集合的替代品。 它旨在提供一个连续的固定长度数组,可以访问,排序和搜索,而无需任何运行时分配 。 此实现区分数组的“容量”(它可包含的最大对象数)和数组的“计数”(插入到数组中的当前数目)。 诸如set()和remove()之类的操作只能对已经显式添加()的对象进行操作; 也就是说,大于getCount()但小于getCapacity()的索引不能单独使用。


I'm making a game in Java. I need some solution for my current runtime allocation, caused by my ArrayList. Every single minute or 30 seconds the garbage collector starts to runs because of I am calling for draw and updates-method through this collection.

How should I be able to do a non runtime allocation solution?

Thanks in advance and if needed, my code is posted below from my Manager class which contains the ArrayList of objects.:

Some code:

@Override
public void draw(GL10 gl) {
  final int size = objects.size();
  for(int x = 0; x < size; x++) {
    Object object = objects.get(x);
    object.draw(gl);
  }
}

public void add(Object parent) {
  objects.add(parent);
}

     //Get collection, and later we call the draw function from these objects
public ArrayList<Object> getObjects() {
   return objects;
}

public int getNumberOfObjects() {
   return objects.size();
}

More explanation: The reason I mix with this is because (1) I see that the ArrayList implementation is slow and causing lags and (2) that I want to merge the objects/components together. When firing an update call from my Thread-class, it goes through my collection, send things down the tree/graph using the Manager's update function.

When looking at an Open Source project, Replica Island, I found that he used an alternative class FixedSizeArray that he wrotes on his own. Since I'm not that good at Java, I wanted to make things easier and now I'm looking for another solution. And at last, he explained WHY he made the special class:

FixedSizeArray is an alternative to a standard Java collection like ArrayList. It is designed to provide a contiguous array of fixed length which can be accessed, sorted, and searched without requiring any runtime allocation. This implementation makes a distinction between the "capacity" of an array (the maximum number of objects it can contain) and the "count" of an array (the current number of objects inserted into the array). Operations such as set() and remove() can only operate on objects that have been explicitly add()-ed to the array; that is, indexes larger than getCount() but smaller than getCapacity() can't be used on their own.


原文:https://stackoverflow.com/questions/4382021
更新时间:2023-07-10 08:07

最满意答案

创建一个新列。 在该列中,创建一个公式,如果“问题类型”为“错误”且“状态”为“已关闭”,则返回1。 否则返回0.对列进行求和。

示例公式

=IF(AND(B2="closed",C2="bug"), 1, 0)

这假定列B具有问题类型,列C具有状态,并且公式在列D中

我在Excel中试过这个,不确定这是不是你正在使用的。


Create a new column. In that column, create a formula that returns 1 if 'Issue Type' is "Bug" and 'Status' is "Closed". Otherwise return 0. Sum the column.

Example formula

=IF(AND(B2="closed",C2="bug"), 1, 0)

This assumes column B has Issue Type, column C has status, and the formula is in Column D

I tried this in Excel, not sure if that's what you are using.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。