Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libGDX Array class benefits

Tags:

libgdx

The javadoc of libGDX Array class says: A resizable, ordered or unordered array of objects. If unordered, this class avoids a memory copy when removing elements (the last element is moved to the removed element's position).
Is the elements removal improvement the only advantage of this class or there are others?
In other words - if I'm not planning to remove elements from my list at all can I live with ArrayList?

like image 966
Chanandler Bong Avatar asked Feb 10 '15 09:02

Chanandler Bong


People also ask

Why use libGDX?

Well Proven libGDX is a well proven and reliable framework with a sound base and documentation. Furthermore, there are plenty of gamesbuilt on top of libGDX, many of which are open source. Active Community Get great support from a very welcoming communityof game and application developers or take a look at our extensive third-party ecosystem.

Where can I play libGDX games?

The libGDX Community libGDX has a very active community on various platforms, including Discord, Reddit and Stack Overflow. If you are looking for a place to start, our Discord server is most definitely the right place. Find out more Game Jams Our community regularly offers game jams for libGDX centered around different themes.

What's new at libGDX Jam 2022?

libGDX Jam June 2022 June 1, 2022 With our 21st collaboration, the libGDX Jam continues the time honoured tradition of making awesome games using the best framework out there. We encourage ca... libGDX 1.11.0 May 11, 2022 We are proud to present a new major release of libGDX: version 1.11.0! libGDX Jam March 2022 February 28, 2022


1 Answers

Array is actually not the only "replacement" of standard Java collection classes. There are many more like ObjectSet or IntIntMap. You can find all of them here.

They are mostly optimized to avoid garbage collection as much as possible. They do this in many ways.

One way is the one you already pointed out, by trying to avoid memory copies when possible, for example in case of a removal of an element in an Array.

Furthermore they re-use the iterators. The standard java collections do not do this, which is why there will be a new Iterator being created every time you are iterating over the collection.

Another way is the use of primitives, which avoids the creation of Objects due to autoboxing. IntIntMap for example has int keys and int values. The standard java HashMap<Integer, Integer> cannot deal with primitives which will result in many autoboxed int -> Integer.

You should always try to stick to the libgdx classes whenever you can, especially on mobile devices. On desktop the garbage collector is usually so fast that you won't notice it, but even there it can result in ugly FPS-lags.

like image 199
noone Avatar answered Sep 28 '22 06:09

noone