Memory Generating Vec2fs

About Monkey 2 Forums Monkey 2 Programming Help Memory Generating Vec2fs

This topic contains 3 replies, has 2 voices, and was last updated by  Matthew Smith 3 years ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #1541

    Matthew Smith

    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?



    Matthew Smith

    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.]


    Mark Sibly

    ‘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.


    Matthew Smith

    Great – thanks Mark!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.