Пример #1
0
        /// <summary>Writes JSON array with the list of allocations.</summary>
        public void BuildStatsString([NativeTypeName("JsonWriter&")] ref D3D12MA_JsonWriter json)
        {
            using D3D12MA_MutexLockRead @lock = new(ref m_Mutex, m_useMutex != 0);

            json.BeginArray();
            for (D3D12MA_Allocation *alloc = m_AllocationList.Front();
                 alloc != null; alloc = D3D12MA_IntrusiveLinkedList <D3D12MA_Allocation> .GetNext(alloc))
            {
                json.BeginObject(true);
                json.AddAllocationToObject(alloc);
                json.EndObject();
            }
            json.EndArray();
        }
        /// <summary>Builds and returns statistics as a string in JSON format, including the list of allocations with their parameters.</summary>
        /// <param name="ppStatsString">Must be freed using <see cref="FreeStatsString"/>.</param>
        public void BuildStatsString([NativeTypeName("WCHAR**")] ushort **ppStatsString)
        {
            D3D12MA_ASSERT((D3D12MA_DEBUG_LEVEL > 0) && (ppStatsString != null));

            using var debugGlobalMutexLock = D3D12MA_DEBUG_GLOBAL_MUTEX_LOCK();

            using var sb = new D3D12MA_StringBuilder(ref m_AllocationCallbacks);

            using (var json = new D3D12MA_JsonWriter(ref m_AllocationCallbacks, &sb))
            {
                D3D12MA_HEAVY_ASSERT((D3D12MA_DEBUG_LEVEL > 1) && m_Metadata.Validate());
                m_Metadata.WriteAllocationInfoToJson(&json);
            }

            nuint   length = sb.GetLength();
            ushort *result = AllocateArray <ushort>(ref m_AllocationCallbacks, length + 1);

            _ = memcpy(result, sb.GetData(), length * sizeof(ushort));
            result[length] = '\0';
            *ppStatsString = result;
        }