D
D
Denis Bredun2020-07-30 19:09:03
C++ / C#
Denis Bredun, 2020-07-30 19:09:03

Can there be an object transition from SOH to LOH and vice versa? If so, what processes are taking place at this time? Simple transition or something else?

Can there be an object transition from SOH to LOH and vice versa? If so, what processes are taking place at this time? Simple transition or something else?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ayazer, 2020-07-30
@Luffy1

no, it can't
upd:
don't confuse the total memory footprint with the size of the object. Loh will contain a conditional array of 100mb/large string. But the object that refers to it is not, because it will only contain a link weighing a couple of bytes.
I suspect you were thinking something like this

public class TestClass
    {
        public byte[] Bytes;

        public TestClass(byte[] bytes)
        {
            Bytes = bytes;
        }

        public void Upd()
        {
            Bytes = new byte[101 * 1024 * 1024];
        }
    }

...

    static void Main(string[] args)
    {
        var data = new TestClass[3];

        for (int i = 0; i < 3; i++)
        {
            data[i] = new TestClass(new byte[1]);
        }

        data[1].Upd();
    }

but no, this will not force the object to be re-evaluated with soh -> loh, because only the array will get into loh, and the object will just have a reference. And if you look into the memory - you can see
5f23ca2621fda807535079.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question