Raudius

Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • in reply to: Structs and Garbage Collection #6089

    Raudius
    Participant

    Damn you’re right parameters are much faster than structs! A lot faster!

    I even made my own test to check the speed difference for a similar implementation  to the one in my game, and primitives values are significantly faster. As I understand it this has to do with the time it takes to copy structs from one method stack to the next.

    I also found that using Getters to get the primitives also significantly affects the time it takes. I assume this is also to do with copying the (“pass-by-value”) value from the one method stack to the next as opposed to just reading it directly from the class’ memory in the heap.

    I may have to consider changing my game to just passing the primitives separately (instead of combining them inside a struct) since the performance impact is so much more than I anticipated.

    Thanks for the heads up!

    <!–more–>

    in reply to: Structs and Garbage Collection #6085

    Raudius
    Participant

    I think for my specific case I’d rather be creating structs than objects since they are a one time use thing and creating objects would drastically increase the load on the GC, right?

    I am just using “Rect” structs as a more convenient way to pass primitives (i.e. coordinates and dimensions for hit testing) and just wanted to make sure I am not making my game terribly inefficient in the process.

    in reply to: Structs and Garbage Collection #6071

    Raudius
    Participant

    Thanks! I suppose it always pays to check the docs and forums.

    So creating a struct and passing it around instead of primitives is basically the same as both the primitives and structs are “pass by value”.

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