예제 #1
0
        private unsafe string GetModelJSON(int startIteration, int numIteration)
        {
            long bufLen = 2L << 15;

            byte[] buffer = new byte[bufLen];
            long   size   = 0L;

            fixed(byte *ptr = buffer)
            PInvokeException.Check(PInvoke.BoosterDumpModel(Handle, startIteration, numIteration, bufLen, ref size, ptr),
                                   nameof(PInvoke.BoosterDumpModel));

            // If buffer size is not enough, reallocate buffer and get again.
            if (size > bufLen)
            {
                bufLen = size;
                buffer = new byte[bufLen];

                fixed(byte *ptr = buffer)
                PInvokeException.Check(PInvoke.BoosterDumpModel(Handle, startIteration, numIteration, bufLen, ref size, ptr),
                                       nameof(PInvoke.BoosterDumpModel));
            }
            byte[] content = new byte[size];
            Array.Copy(buffer, content, size);

            fixed(byte *ptr = content)
            return(Marshal.PtrToStringAnsi((IntPtr)ptr));
        }