Use of irr::array: VERY recommended!

A forum to store posts deemed exceptionally wise and useful
Post Reply
linkoraclehero
Posts: 81
Joined: Sat Sep 09, 2006 6:46 am

Use of irr::array: VERY recommended!

Post by linkoraclehero »

While I haven't looked into the backend of what separates irr::array from vector, I have come to find that irr::array is a much more durable and powerful implementation of dynamic array creation and usage, especially inside Irrlicht.

I stumbled upon this when I was using a vector for an array of vertexes and indexes, which produced extra data. Simply replacing vector with core::array solved EVERYTHING!

This should be duly noted somewhere, probably not here, but probably in the tutorials for those like me who need to make dynamic models within their own engine, since some things shouldn't rely on external model files.
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

I wouldn't say that so general. I always use Irrlicht arrays when I need to access specific entries directly (e.g. the 3rd), but when I just have to iterate I use the list (I guess it's faster - though I haven't tested that). Works fine for me.
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

Initially I have simply used array everywhere rather than list.

If I want to iterate over the array, I grab the .pointer() to the data of the array, then iterate over it like a normal C array. I believe this is much faster than iterating using irrArray. At the same time, I can get direct access if I want using irrArray directly.

I believe that the list is only better if you are performing many insertions and deletions, as it does not need to shift the elements.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

Ulf wrote:I believe that the list is only better if you are performing many insertions and deletions, as it does not need to shift the elements.
The 2nd table is interesting.
"Whoops..."
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

I only had a quick think, but isn't the table incorrect?

Excuse me if I misunderstand but for the list, if it takes O(N) to access the middle, must it not take O(N) to insert in the middle? You need to iterate to the middle first to insert a new item.

If it is a sorted list, it will be O(logN).
Whereas if the array is sorted, inserting at the start or middle will always be O(N).
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Ulf wrote: Excuse me if I misunderstand but for the list, if it takes O(N) to access the middle, must it not take O(N) to insert in the middle? You need to iterate to the middle first to insert a new item..
Technicaly correct but: you are not randomly inserting in the middle most of the time you will already have your handle. For example my Entities are in a array for quick id acces over the network and at the same time in a list. they store both the array id and the list iterator to there location to quickly erase them or insert something behind them.
Another place where i use it is in my octreescenemanager. evey cell has a list of entries and bc when a object is moving it needs to be quickly removed and added to different cells so it stores the list iterator along the way.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Post Reply