_tomanagedarray temp objects allocations

This commit is contained in:
2025-04-28 23:03:36 +03:00
parent 96d35acefd
commit f10dab59de
2 changed files with 58 additions and 27 deletions

View File

@@ -40,6 +40,8 @@ namespace
valueClass = Scripting::FindClass(valueTypename);
}
}
extern Array<MObject*> MUtils::ObjectsTemp;
StringView MUtils::ToString(MString* str)
{

View File

@@ -41,6 +41,8 @@ namespace MUtils
extern FLAXENGINE_API MTypeObject* BoxVariantType(const VariantType& value);
extern FLAXENGINE_API Variant UnboxVariant(MObject* value);
extern FLAXENGINE_API MObject* BoxVariant(const Variant& value);
extern Array<MObject*> ObjectsTemp;
}
// Converter for data of type T between managed and unmanaged world
@@ -107,11 +109,14 @@ struct MConverter<String>
{
if (data.Length() == 0)
return;
MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
//MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
static Array<MObject*> objects;
//objects.Clear();
objects.Resize(data.Length());
for (int32 i = 0; i < data.Length(); i++)
objects[i] = (MObject*)MUtils::ToString(data.Get()[i]);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects, data.Length()));
Allocator::Free(objects);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects.Get(), data.Length()));
//Allocator::Free(objects);
}
void ToNativeArray(Span<String>& result, const MArray* data)
@@ -140,11 +145,14 @@ struct MConverter<StringAnsi>
{
if (data.Length() == 0)
return;
auto* objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
//auto* objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
static Array<MObject*> objects;
//objects.Clear();
objects.Resize(data.Length());
for (int32 i = 0; i < data.Length(); i++)
objects[i] = (MObject*)MUtils::ToString(data.Get()[i]);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects, data.Length()));
Allocator::Free(objects);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects.Get(), data.Length()));
//Allocator::Free(objects);
}
void ToNativeArray(Span<StringAnsi>& result, const MArray* data)
@@ -173,11 +181,14 @@ struct MConverter<StringView>
{
if (data.Length() == 0)
return;
MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
//MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
static Array<MObject*> objects;
//objects.Clear();
objects.Resize(data.Length());
for (int32 i = 0; i < data.Length(); i++)
objects[i] = (MObject*)MUtils::ToString(data.Get()[i]);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects, data.Length()));
Allocator::Free(objects);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects.Get(), data.Length()));
//Allocator::Free(objects);
}
void ToNativeArray(Span<StringView>& result, const MArray* data)
@@ -206,11 +217,14 @@ struct MConverter<Variant>
{
if (data.Length() == 0)
return;
MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
//MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
static Array<MObject*> objects;
//objects.Clear();
objects.Resize(data.Length());
for (int32 i = 0; i < data.Length(); i++)
objects[i] = MUtils::BoxVariant(data[i]);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects, data.Length()));
Allocator::Free(objects);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects.Get(), data.Length()));
//Allocator::Free(objects);
}
void ToNativeArray(Span<Variant>& result, const MArray* data)
@@ -239,11 +253,14 @@ struct MConverter<T*, typename TEnableIf<TIsBaseOf<class ScriptingObject, T>::Va
{
if (data.Length() == 0)
return;
MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
//MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
static Array<MObject*> objects;
//objects.Clear();
objects.Resize(data.Length());
for (int32 i = 0; i < data.Length(); i++)
objects[i] = data.Get()[i] ? data.Get()[i]->GetOrCreateManagedInstance() : nullptr;
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects, data.Length()));
Allocator::Free(objects);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects.Get(), data.Length()));
//Allocator::Free(objects);
}
void ToNativeArray(Span<T*>& result, const MArray* data)
@@ -267,11 +284,14 @@ struct MConverter<T, typename TEnableIf<TIsBaseOf<class ScriptingObject, T>::Val
{
if (data.Length() == 0)
return;
MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
//MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
static Array<MObject*> objects;
//objects.Clear();
objects.Resize(data.Length());
for (int32 i = 0; i < data.Length(); i++)
objects[i] = data.Get()[i].GetOrCreateManagedInstance();
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects, data.Length()));
Allocator::Free(objects);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects.Get(), data.Length()));
//Allocator::Free(objects);
}
};
@@ -296,11 +316,14 @@ struct MConverter<ScriptingObjectReference<T>>
{
if (data.Length() == 0)
return;
MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
//MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
static Array<MObject*> objects;
//objects.Clear();
objects.Resize(data.Length());
for (int32 i = 0; i < data.Length(); i++)
objects[i] = data[i].GetManagedInstance();
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects, data.Length()));
Allocator::Free(objects);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects.Get(), data.Length()));
//Allocator::Free(objects);
}
void ToNativeArray(Span<ScriptingObjectReference<T>>& result, const MArray* data)
@@ -332,11 +355,14 @@ struct MConverter<AssetReference<T>>
{
if (data.Length() == 0)
return;
MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
//MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
static Array<MObject*> objects;
//objects.Clear();
objects.Resize(data.Length());
for (int32 i = 0; i < data.Length(); i++)
objects[i] = data[i].GetManagedInstance();
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects, data.Length()));
Allocator::Free(objects);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects.Get(), data.Length()));
//Allocator::Free(objects);
}
void ToNativeArray(Span<AssetReference<T>>& result, const MArray* data)
@@ -357,11 +383,14 @@ struct MConverter<SoftAssetReference<T>>
{
if (data.Length() == 0)
return;
MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
//MObject** objects = (MObject**)Allocator::Allocate(data.Length() * sizeof(MObject*));
static Array<MObject*> objects;
//objects.Clear();
objects.Resize(data.Length());
for (int32 i = 0; i < data.Length(); i++)
objects[i] = data[i].GetManagedInstance();
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects, data.Length()));
Allocator::Free(objects);
MCore::GC::WriteArrayRef(result, Span<MObject*>(objects.Get(), data.Length()));
//Allocator::Free(objects);
}
void ToNativeArray(Span<SoftAssetReference<T>>& result, const MArray* data)