Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

android - Why did the sample google realtime drawing app choose an ArrayList over a LinkedList for drawing on the Canvas?

I'm trying to code a realtime drawing App like the sample one Google has

https://github.com/googlearchive/AndroidDrawing

but I am curious to why they chose Arraylist<Point> data structure for adding points to the screen when drawing on the canvas. (It's adding about 100 Point objects when I draw a line )

https://github.com/googlearchive/AndroidDrawing/blob/master/app/src/main/java/com/firebase/drawing/Segment.java

The list of points represent one line.

Since an ArrayList is an implementation of a dynamic array. You have to constantly add new entries (points in this case) to the back of the container. Dynamic arrays have to be reallocated every time you change their size which means the entire contents have to be copied to a new block of memory. Linked lists, on the other hand, allow you to insert or remove entries without having to reallocate the rest of the list. Linked lists are much faster than dynamic arrays when you do frequent modification of the elements like you're doing here.

Why not use a LinkedList?

question from:https://stackoverflow.com/questions/65853190/why-did-the-sample-google-realtime-drawing-app-choose-an-arraylist-over-a-linked

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...