Dumb question which I think I know the answer but want to clarify. I’m playing around with a tile based game with objects moving pixel by pixel. To verify the tile location of the object I’ve created a property returning a Vec2f which generates each time it’s called (potentially called 40-50+ times per cycle when verifying tile stuff).
This would eventually be a memory issue wouldn’t it?
There is a bit of a discussion here about structs and memory allocation which Vec is:
So it might be ok?
I could also change it to create the Vec2f on creation of the object and update X,Y before returning rather than generating a new one each call.
[Update: Ran it both ways for 10mins and the Memory Manager crept up a couple of meg at the start and was stable after that – so no real issue by the looks.]
‘New Struct’ is always free in terms of memory management, as the new value is always created ‘on the stack’ which has no runtime cost.
This is the cool thing about ‘value types’ – since they’re always copied and therefore never ‘shared’ via references, they don’t have to be managed in any way.
‘New Class’ is never free, but hopefully pretty quick – and it’ll get quicker as I can inline more here.
Great – thanks Mark!
You must be logged in to reply to this topic.
Monkey2 is an easy to use, cross platform, games oriented programming language from Blitz Research.