Random increase in memory usage?

Revision en1, by caterpillow, 2023-11-01 15:35:38

Hi,

I was writing a solution for Sereja and Brackets where I used a struct called DSU. However, the struct contained some unnecessary code and used generics, so I removed the struct and moved the relevant code outside. This somehow resulted in slower execution with over 50% more memory usage.

After playing around, I created these two submissions where the only difference as far as I could see was my usage of a struct. Submission 1 (struct, faster) and Submission 2 (no struct, slower).

I'm still pretty new to C++ and I come from a Java/Python background, so if someone could explain this behavior it would be very much appreciated.

Thanks!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English caterpillow 2023-11-01 15:35:38 862 Initial revision (published)