Skip to content

Commit

Permalink
.NET: Reduce heap allocation on Method::Invoke calls
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Apr 22, 2024
1 parent c06a86e commit e9df508
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions csharp-api/REFrameworkNET/Method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ ::reframework::InvokeRet Method::Invoke_Internal(System::Object^ obj, array<Syst
throw gcnew System::InvalidOperationException(errorStr);
}

std::vector<void*> args2{};
//std::vector<void*> args2{};
std::array<void*, 32> args2{}; // what function has more than 32 arguments?

if (args != nullptr && args->Length > 0) {
args2.resize(args->Length);

for (int i = 0; i < args->Length; ++i) try {
if (args[i] == nullptr) {
args2[i] = nullptr;
Expand Down Expand Up @@ -250,7 +249,9 @@ ::reframework::InvokeRet Method::Invoke_Internal(System::Object^ obj, array<Syst
System::Console::WriteLine("Error converting object: " + e->Message);
}

return m_method->invoke((reframework::API::ManagedObject*)obj_ptr, args2);
const auto argcount = args != nullptr ? args->Length : 0;

return m_method->invoke((::reframework::API::ManagedObject*)obj_ptr, std::span<void*>(args2.data(), argcount));
}

bool Method::HandleInvokeMember_Internal(System::Object^ obj, array<System::Object^>^ args, System::Object^% result) {
Expand Down

0 comments on commit e9df508

Please sign in to comment.