DreiDe - 3D Engine

BlitzMax Forums/BlitzMax Programming/DreiDe - 3D Engine

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Olli,

your code might be way more efficient using basic fields instead of arrays for you structure components.

Using arrays in types, even for basic types like int or float and even if declared in the type with a constant size does generate an extra object for the array part. It is not embedded in the structure like for instance in C/C++.

The result is negative in several ways:
- your methods might be slower than possible because accessing each component needs reading the address of the components array followed by the final read of the component. That's more instructions than necessary *and* it has to read from another memory address which may lead to cache misses which easily may cost more cycles than the calculations.

- Alloc/Free of the types will be slower than necessary because of the additional array object used.

- Memory usage will be higher than necessary. BlitzMax' per alloc overhead is 8 byte, using for instance a TVector3 using 3 float fields x, y, z allocates 20bytes (3*4+8), using a float[3] field allocates 32bytes (2*8 +3*4 + 4 - the last used by the field pointing to the array)