非运行时分配解决方案 - 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
最满意答案
创建一个新列。 在该列中,创建一个公式,如果“问题类型”为“错误”且“状态”为“已关闭”,则返回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.
相关问答
更多-
当另一列等于某个列时,计算一列中的出现次数(Count occurrences in one column when another column is equal to something)[2022-04-05]
创建一个新列。 在该列中,创建一个公式,如果“问题类型”为“错误”且“状态”为“已关闭”,则返回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 ... -
计算另一列中一列的子串的出现次数(Counting the occurrences of a substring from one column within another column)[2023-08-15]
我认为需要通过正则表达式连接并加入Name所有值,然后通过MultiLabelBinarizer创建指标列并通过reindex添加所有缺少的列: s = df1['Name'] + ' scored' pat = r'\b{}\b'.format('|'.join(s)) from sklearn.preprocessing import MultiLabelBinarizer mlb = MultiLabelBinarizer() df = pd.DataFrame(mlb.fit_transform ... -
如果最后一列等于“R”,那么......有可能吗?(If the last column is equal “R” then… Is it possible? In unix)[2022-12-23]
假设按空格分隔的更通用的代码: case $var in (*\ R) printf "%s\n" "$var" esac 要么: if [ "${var##* }" = R ]; then printf "%s\n" "$var" fi More universal code assuming separation by spaces: case $var in (*\ R) printf "%s\n" "$var" esac Or: if [ "${var##* }" = R ]; t ... -
这会做 df.fillna('').apply(lambda x : x.index==x.name).astype(int).replace(0,"") Out[563]: A B C index D E B 1 C 1 This will do df.fillna('').apply(lambda x : x.index==x.name).astype(int).replace(0 ...
-
这适用于给定的数据: select t1.ID, t1.type, count(t2.type) as `count` from table1 t1 left join table1 t2 on t2.type = 'fruits' and t2.reference like concat('%"', t1.ID, '"%') where t1.`type` <> 'fruits' group by t1.ID, t1.type; 结果: | ID | type | count | |--- ...
-
SUM(CASE WHEN StatusID NOT IN (5, 7, 42) THEN 1 ELSE 0 END) AS Valid, SUM(CASE WHEN StatusID IN (5, 7, 42) THEN 1 ELSE 0 END) AS Invalid, SUM(CASE WHEN StatusId = 4 THEN 1 ELSE 0 END) AS 'Consults Booked' SUM(CASE WHEN StatusID NOT IN (5, 7, 42) THEN 1 EL ...
-
您可以使用CASE表达式在聚合期间执行条件检查。 案例陈述确定了条件结果。 例如,您可以使用: select evaluation_result , count(*) AS total , sum(case when success='true' and result='a' then 1 else 0 end) AS num_successful , sum(case when success='true' and result='a' then 1 else 0 end)/count(*) AS suc ...
-
这是一个awk和sort的快速: awk ' { counts[$1]++; # Increment count of lines. totals[$1] += $2; # Accumulate sum of second column. } END { # Iterate over all first-column values. for (x in counts) { print x, counts[x], totals[x]; } } ' ...
-
扩展OP的解决方案以使用dplyr和data.table选项可以如下: library(dplyr) library(data.table) df %>% group_by(Store,RTU) %>% mutate(Flag = rleid(Temperature)) %>% group_by(Flag) %>% mutate(Flag_Temperature_check = ifelse(row_number() <= 3, "Ok","Discard")) # # A tibble: 18 ...
-
您的解释不是很清楚,但根据您的示例数据和所需的输出,您可以通过外部连接到基表的两个子查询来完成此操作,如下所示: select a.id, coalesce(b.id_1_count,0), coalesce(c.id_2_count,0) from so15273831 a left outer join ( select id_1, count(*) as id_1_count from so15273831 group by id_1 ) b on b.id_1 = a.id ...