Home > Mobile >  Very large List frequently GC, cause caton, how to break
Very large List frequently GC, cause caton, how to break

Time:12-18

Bresenham line drawing algorithm
I put each line every point of x, y coordinates to list Inside the
The final list the size of the hundreds of W, the convention has more than 1000 W
This leads to frequent GC, easily jammed

After get all the points corresponding to the coordinates of the turning RGBA_8888 bitmap
Then show to the ImageView

This is Bresenham line drawing algorithm
X0, y0 line starts at the coordinates of the
X1, y1 line at the end of the coordinates of the

Private void getPXpoint (int x0, int y0, int x1, int y1) throws OutOfMemoryError {
If (x0 & lt; 0 | | x0 & gt; Screen_width * 3)
return;
Int x=x0;
Int y=y0;

Int w=x1 - x0;
Int h=y1 - y0;

Int dx1=w & lt; 0? 1: (w & gt; 0? 1:0);
Int dy1=h & lt; 0? 1: (h & gt; 0? 1:0);

Int dx2=w & lt; 0? 1: (w & gt; 0? 1:0);
Int dy2=0;

Int fastStep=Math. Abs (w);
Int slowStep=Math. Abs (h);
If (fastStep & lt;={slowStep)
FastStep=Math. Abs (h);
SlowStep=Math. Abs (w);

Dx2=0;
Dy2=h & lt; 0? 1: (h & gt; 0? 1:0);
}
Int numerator=fastStep & gt;> 1;

For (int I=0; i <=fastStep; I++) {

Point Point=new Point (x, y);
Points. The add (point);//each point of the x, y coordinates save
The numerator +=slowStep;
If (numerator & gt;={fastStep)
Numerator -=fastStep;
X +=dx1;
Y +=dy1;
} else {
X +=dx2;
Y +=dy2;
}
}
}

CodePudding user response:

1. Used on besides?

CodePudding user response:

reference 1st floor can't write code monkey reply:
1. Used in addition to please check?

Used to clear or empty

CodePudding user response:

This is you pick up some more rapidly than linear velocity,,,, can you give the list to set maximum and reached the maximum value, lose some coordinates

CodePudding user response:

Performance problems generally can reduce computational complexity and increase the cache to solve, which you can reuse Point, don't every time new

CodePudding user response:



refer to 4th floor can't write code monkey reply:
this is you pick up some more rapidly than linear velocity,,,, can you give the list to set maximum and reached maximum, losing some coordinate

Coordinates cannot be lost, I want to get all coordinates, and then turn RGBA_8888 bitmap

CodePudding user response:

A bitmap can hold not?

CodePudding user response:

Points are constantly produce?

If so, let the deposit points into the queue, another thread queue and drawing, queue size limit, involves more than the queue length, first in first out,
  • Related