Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p><em>You're allocating objects during runtime.</em> 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).</p> <p>That said; <em>I'm not sure</em> 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 <code>onTouchEvent():</code></p> <pre><code>new Element(getResources(), (int) event.getX(), (int) event.getY()) </code></pre> <p>You should have something like <code>mElement.add(objectPool.allocate())</code>, 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.</p> <blockquote> <p>With the 26th element the frame rate drops to 25fps.</p> </blockquote> <p>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). </p> <p>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 <code>Canvas</code> on an <code>onTouchEvent()</code> 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 <strong>Swedish</strong>, but I think you should be able to understand, since the variables and methods are in <strong>English</strong>. :)</p> <p><strong>Side note</strong>: You wrote that you've tried (and even success) with removing the behaviour by making your <code>Bitmap</code> <code>static</code>. As it is right now, your elements have different instances of a <code>Bitmap</code>, which will make you allocate a new <code>Bitmap</code> everytime you're constructing a new object. That means that every object is pointing to a different <code>Bitmap</code> when they are using the same resource. <code>static</code> is a fully valid solution (although a magic number of 25 seems wierd). </p> <p>This <code>Bitmap</code> case can be compared to the <code>OpenGL</code> 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 <code>static</code>), but still same resource. </p> <p><strong>EDIT</strong>:</p> <p><a href="http://code.google.com/p/viktor-lanner/downloads/detail?name=Memory_Pool_pattern_PART_THREE_SOURCE.zip" rel="nofollow">Here is my sample application for Android</a> that demonstrates the Memory Pool.</p> <p>Regarding your solution with <code>BitmapFactory</code>, that probably depends on how that class works. I'm not sure, but I think that one of the <code>decode...()</code> methods generates a new <code>Bitmap</code> even if it is the same resource. It can be the case that <code>new BufferedInputStream(res.openRawResource(R.drawable.icon))</code> is reusing the <code>BufferedInputStream</code> from memory, although, that is a big guess.</p> <p>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 <code>new Element(bitmapReference, ...)</code> instead. In that way, you're only allocating it once and every element is pointing to the same <code>Bitmap</code> in memory.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload