与Galaxy Tab的奇怪的性能问题 [英] Weird performance issue with Galaxy Tab

查看:121
本文介绍了与Galaxy Tab的奇怪的性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在2D教程,并能测试上三星Galaxy Tab我目前的教程部分。

I am working on a 2d tutorial and was able to test my current tutorial part on a Samsung Galaxy Tab.

本教程简单随机移动的默认图标在屏幕上。随着抽头我创建一个新的动态图标。一切工作正常(不断60fps的),在Galaxy只要我有25元或更少的屏幕上。

The tutorial simply moves the default icon randomly over the screen. With a tap I create a new moving icon. Everything works fine (constantly 60fps) on the Galaxy as long as I have 25 elements or less on the screen.

第26个元素的帧速率下降到25fps的。

With the 26th element the frame rate drops to 25fps.

当我改变形象,以一个更大之一的尺寸/尺寸,我到了26号元素之前不到25fps的。没关系。但在某些元素没有真正再现数目从丢帧(大多超过)10fps的到1fps。

When I change the size/dimension of the image to a much bigger one, I reach less than 25fps before the 26th element. Thats ok. But at some not really reproducible number of elements the frame drops from (mostly more than) 10fps to 1fps.

在我的Nexus One我可以加150元,而且还有50fps的。

On my Nexus One I can add 150 elements and still have 50fps.

我做了什么:我改变了位图变量静态的,所以并不是每一个元素都有自己的形象,但都使用相同的。这取出的行为,但我怀疑这个解决方案是一个很好的一个。 25个神奇的数字所暗示的,我可以以这种方式只用25种不同的图像。

What I have done: I changed the bitmap variable to a static one, so not every element has his own image but all use the same. That removed the behavior, but I doubt this solution is a good one. The magic number of 25 would suggest that I can use only 25 different images in that way.

是否有人有任何想法可能导致此行为?它是三星的修改Android版本中的错误?

Does someone have any idea what can cause this behavior? Is it a bug in the modified android version of Samsung?

我的样本Eclipse项目可。我想AP preciate如果一些三星车主会检查他们的表现与样品。

My sample eclipse project is available. I would appreciate if some Samsung owner would check their performance with the sample.

修改

一个同事找到了解决办法。他改变了位图是从

A colleague found a solution. He changed the way the bitmap is loaded from

mBitmap = BitmapFactory.decodeResource(res, R.drawable.icon);

mBitmap = BitmapFactory.decodeStream(new BufferedInputStream(res.openRawResource(R.drawable.icon)));

但是,我们仍然没有真正得到它,为什么是这样工作的...

But we still don't really get it why it works this way...

推荐答案

嗯,我一直在找你的项目,一切似乎是美好的,但我有一个想法,什么是造成你的帧速率下降。

Well, I've been looking on your project and everything seems to be fine, but I have one idea about what's causing you the frame rate drop.

你在运行时分配对象。的如果你不这样做,就会让你创建的所有对象的开始,因此,你应该直接看到一个显著下降(如果我的解决方案没有按T解决你的问题)。

You're allocating objects during runtime. If you don't do that, it will make you create all objects at start, and therefore you should notice a significant drop directly (if my solution doesn't solve your problem).

这表示; 我不知道对象池的是否会解决你的问题,但你可以试试。在初始化,而不是把这个调用的onTouchEvent()构造函数和你的对象:

That said; I'm not sure whether an object pool will solve your problem, but you can try. Initialize your objects in a constructor and instead of making this call in onTouchEvent():

new Element(getResources(), (int) event.getX(), (int) event.getY())

您应该有一些像 mElement.add(objectPool.allocate()),其中,对象池发现池中未使用的对象。同时,我们应该有一个指定的对象的数量在对象池,并从那里,你可以检查它是否是导致此错误的分配或如果是别的东西。

You should have something like mElement.add(objectPool.allocate()), where the object pool finds an unused object in the pool. Also, we should have a specified amount of objects in that object pool and from there you can check if it is the allocating that is causing this error or if it is something else.

第26个元素的帧速率下降到25fps的。

With the 26th element the frame rate drops to 25fps.

当(或如果)你实现这一点,你应该看到直接的帧率下降(如果这不能解决你的问题虽然),因为对象池会让你分配一个固定的金额(如100也许要素是什么?)在启动(但你不使用它们在视觉上)。

When (or if) you implements this, you should see the frame rate drop directly (if this doesn't solve your problem though), since the object pool will make you allocating a fixed amount (e.g. maybe 100 elements?) at start (but you're not using them visually).

另外,我已经使用了内存池模式(对象池)在我的示例应用程序为Android之一。在该样本;我加上一行到画布的onTouchEvent()使用对象池(不运行时分配)。在该源$ C ​​$ C,你可以很容易地改变总金额的对象,并检查出来,并自己尝试一下。写评论,如果你想看看我的示例应用程序(和源$ C ​​$ c)和我将很乐意分享它,因为它不是公开。我的意见是瑞典,但我认为你应该能够理解,因为变量和方法都在英国。 :)

Also, I have used the memory pool pattern (object pool) in one of my sample applications for Android. In that sample; I add a line to the Canvas on an onTouchEvent() using an object pool (without allocating during runtime). In that source code you can easily change the total amounts of objects and check it out and try it yourself. Write a comment if you want to look at my sample application (and source code) and I will gladly share it since it's not public yet. My comments are in Swedish, but I think you should be able to understand, since the variables and methods are in English. :)

旁注:你写你已经尝试过(甚至成功)与通过您的位图 <$ C $拆除行为C>静态。因为它是现在,你的元素有一个位图,这将使你分配一个新的位图每次的不同实例你要构造一个新的对象。这意味着,每一个对象指向一个不同的位图的时候都用相同的资源。 静态是一个完全有效的解决方案(虽然25神奇的数字似乎奇怪)。

Side note: You wrote that you've tried (and even success) with removing the behaviour by making your Bitmap static. As it is right now, your elements have different instances of a Bitmap, which will make you allocate a new Bitmap everytime you're constructing a new object. That means that every object is pointing to a different Bitmap when they are using the same resource. static is a fully valid solution (although a magic number of 25 seems wierd).

位图情况下,可以比的OpenGL 系统。如果你有这都应该使用相同的资源20个对象,有两种可能的解决方案:他们可以指向同一个VRAM的纹理或他们​​要么可以指向一个不同的VRAM质地(如您的情况下,当你不使用静态),但仍然相同的资源。

This Bitmap case can be compared to the OpenGL system. If you have 20 objects which all should use the same resource, there are two possible solutions: They can point to the same VRAM texture or either they can point to a different VRAM texture (like your case when you're not using static), but still same resource.

修改

<一个href="http://$c$c.google.com/p/viktor-lanner/downloads/detail?name=Memory_Pool_pattern_PART_THREE_SOURCE.zip"相对=nofollow>这是我为Android 的示例应用程序演示内存池。

Here is my sample application for Android that demonstrates the Memory Pool.

关于与 BitmapFactory ,这可能取决于该类工作的解决方案。我不知道,但我认为其中一个德code ...()方法生成一个新的位图即使是相同的资源。它可以是的情况下,新的BufferedInputStream(res.openRawResource(R.drawable.icon))被重复使用的BufferedInputStream 从内存中,虽然,这是一个大猜想。

Regarding your solution with BitmapFactory, that probably depends on how that class works. I'm not sure, but I think that one of the decode...() methods generates a new Bitmap even if it is the same resource. It can be the case that new BufferedInputStream(res.openRawResource(R.drawable.icon)) is reusing the BufferedInputStream from memory, although, that is a big guess.

你应该做的(在这种情况下)是要脱codeA资源,存储从它的面板类的引用,并通过该引用到新元素(bitma preference ,...)代替。这样一来,你只分配一次,每一个元素都指向同一个位图在内存中。

What you should do (in that case) is to decode a resource and store a reference from it in the Panel class and pass that reference into the new Element(bitmapReference, ...) instead. In that way, you're only allocating it once and every element is pointing to the same Bitmap in memory.

这篇关于与Galaxy Tab的奇怪的性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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