Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化保存文件时的内存占用 #831

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Il2CppDumper/Outputs/StructGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ public void WriteScript(string outputDir)
var jsonOptions = new JsonSerializerOptions() { WriteIndented = true, IncludeFields = true };
File.WriteAllText(outputDir + "stringliteral.json", JsonSerializer.Serialize(stringLiterals, jsonOptions), new UTF8Encoding(false));
//写入文件
File.WriteAllText(outputDir + "script.json", JsonSerializer.Serialize(json, jsonOptions));
using (var stream = new FileStream(outputDir + "script.json",FileMode.Create))
{
JsonSerializer.Serialize(stream, json, jsonOptions);
}
//il2cpp.h
for (int i = 0; i < genericClassList.Count; i++)
{
Expand Down Expand Up @@ -428,7 +431,21 @@ public void WriteScript(string outputDir)
sb.Append(headerStruct);
sb.Append(arrayClassHeader);
sb.Append(methodInfoHeader);
File.WriteAllText(outputDir + "il2cpp.h", sb.ToString());
int bufferSize = 4096;
using (StreamWriter writer = new StreamWriter(outputDir + "il2cpp.h", false, Encoding.UTF8, bufferSize))
{
int index = 0;
int length = sb.Length;
char[] buffer = new char[bufferSize];

while (index < length)
{
int count = Math.Min(bufferSize, length - index);
sb.CopyTo(index, buffer, 0, count);
writer.Write(buffer, 0, count);
index += count;
}
}
}

private void AddMetadataUsageTypeInfo(ScriptJson json, uint index, ulong address)
Expand Down