Does golang allow heap data to be stored without GC exposure?

    1 answer 1

    Outside, heap is not, although the language does not guarantee that the objects being created will go there. In implementations, by the way, there’s really no place to go around and heap is used very often.

    And without the influence of GC (in unmanaged heap ) - yes, it is possible , using low-level tools in unsafe packages, syscall , and reflection may be required.

    In a more civilized form, this functionality is presented in the Manual Memory Management library.

    If you look inside, they use unsafe.Pointer , pointer juggling, syscall.Mmap and syscall.Munmap , among others. The author claims that the features of the implementation of interfaces are also used, so that during the next update of the compiler may break.


    In general, yes, but it’s hard and usually a bad idea.

    • There is nothing bad there. If you have a map of 10 ^ 7 keys. It will constantly strain the GC. In java, this is done constantly (out off heap memory) when you need to store huge amounts of data in memory. Thanks for the "mmm"! - TomX01
    • @ TomX01 is a warning to readers who are not very in the subject, but have heard that GC is a priori bad. - D-side