Handmade Hero»Forums»Code
Jimmy Van Broeck
2 posts
Comparison between Fixed array or Fixed mem alloc
I know that Casey doesnt like to do mallocs, callocs, new .... , thats fine.

But whats the difference then eg. in render_group

using a fixed array pieces[4096] or some other number and the Fixed memory he puts aside for storing the render Pieces.

You're always using the same amount of memory. The only thing is in the case of the array you have to calculate how much its using vs saying use 4mb and be done.

In the later case you have more work managing the flat void* memory.

Just my 2cents
J.
Mārtiņš Možeiko
2570 posts / 2 projects
Comparison between Fixed array or Fixed mem alloc
Every render piece takes different amount of memory. By using fixed array you'll be wasting a lot of memory. It may affect performance due to limited size of CPU cache.
Jimmy Van Broeck
2 posts
Comparison between Fixed array or Fixed mem alloc
A Fixed mem alloc is wasting the same kind of memory.
Ok, In a void* you can store alot of different types of struct. But managing that?
Mārtiņš Možeiko
2570 posts / 2 projects
Comparison between Fixed array or Fixed mem alloc
Yes, it's only wasting memory. But not using it. There's a big difference there. Allocating memory doesn't involve any access to this memory so caches are not touched.

Managing that is as easy as adding one number (size of current structure) to another (base pointer). If you are iterating array you are also adding a number for every iteration - i++ or something.