5

I'm not proud of this, but I'm not sure there's a better way of doing this.

Context: texture sheets are massive, so I wanted them to be gced when possible. Problem is, during init, the gc kept collecting the sheets, which added a full 5-10 seconds to load times.

This ensures that the sheets stay in memory until everything is initialized.

Comments
  • 2
    Whenever you have to fight the "gc" there is a better way to design it. You have to find the actual root cause of it.

    Another way is to use Java Native Interface (JNI) to write it in C/C++ which you can handle the memory however you want.
  • 1
    Sounds like it's time for some O(n log n) optimization
  • 3
    This is one of these situations in which I realize the benefit of being able to go low level

    Manual memory management can be a pain, but it is necessary from time to time
  • 0
    @LotsOfCaffeine how the hell does one do assembly in modern times? Or are you referring to demoscene or retrocoding stuff?
  • 0
    @mr-user So much this. a) JNI is great and b) whenever you have to start fiddling with the GC you most likely already fucked up somewhere.
  • 1
    @Parzi I was guessing they were talking about C++/C *shrug*
  • 1
    @Parzi

    we are talking about C/C++

    @Maer

    If you have to mess with "gc" you are fucked due to design error. Try to fix up the design.

    If you cannot fix up the design due to constraint or cannot think up of anything else, use JNI.
  • 0
    @Maer @mr-user how do you manually lay out memory in C?
  • 0
    @mr-user That is what I said. We were in agreement.
  • 1
    @Parzi They just mentioned "memory management" which is rather broad.

    A list of things that can be considered memory management, descending from highlevel to lowlevel:

    - GC calls in Java, then hoping the GC actually collects unreferenced objects

    - C++ allocation via new and deallocation via destructor

    - C alloc calls

    - Assembly level memory mapping

    Since there is reference to JNI, this is probably just about C++ memory allocation - at least I think so.
  • 0
    @Maer you missed the "manual" part?
  • 1
Add Comment