Have a look (Types vs. Arrays)

BlitzMax Forums/BlitzMax Programming/Have a look (Types vs. Arrays)

Jake L.(Posted 2006) [#1]
Hi,

I'm working on a particle-sys atm, just to get comfort with BMax and OGL. I asked me what's faster to use: Types within Types (i.e. Field pos:TVector3) or Arrays (i.e. Field pos#[3]).

So I wrote a test-app with interesting results:
Types are faster to create, faster accessible and use less memory. Not what I expected.

Would you mind to run this for yourself, maybe I got an error in my code.




Dreamora(Posted 2006) [#2]
Test 1

How many elements?100
please wait...
Creating 100 parrays: 0
used memory: 4982
Write to 100 parrays: 0
Read from 100 parrays: 0
-----------------
Creating 100 ptypes: 0
used memory: -3476
Write to 100 ptypes: 0
Read from 100 ptypes: 0


Error here as you clearly see

Test 2

How many elements?100000
please wait...
Creating 100000 parrays: 137
used memory: 4797572
Write to 100000 parrays: 72
Read from 100000 parrays: 5
-----------------
Creating 100000 ptypes: 57
used memory: 3199172
Write to 100000 ptypes: 9
Read from 100000 ptypes: 6



Jake L.(Posted 2006) [#3]
Maybe GCMemAlloced() return wrong values when using low elementcounts - that's all I clearly see.


Chris C(Posted 2006) [#4]
as I understand it GCMemAlloced is the total of a pool of memory, which can contain a bit of unused slack, when the GC releases and object the unused memory is often kept for later use, maybe this is whats is happening

test1 is just using some of the slack and doesnt need to allocate memory from the system because it has enough room in its pool


Jake L.(Posted 2006) [#5]
Forget 'bout GCMemAlloced...
Am I the only one beeing suprised that types within types are faster than arrays?


tonyg(Posted 2006) [#6]
Not sure but isn't this because you're directly accessing the link for the object rather than accessing the object via a list? It's normally the list access vs indexed acces that makes arrays faster.