Skip to content

fix: store memoryUsed as long long instead of int#292

Merged
alphagocc merged 14 commits intoProject-LemonLime:masterfrom
ZnPdCo:int64-for-used-memory
Apr 9, 2026
Merged

fix: store memoryUsed as long long instead of int#292
alphagocc merged 14 commits intoProject-LemonLime:masterfrom
ZnPdCo:int64-for-used-memory

Conversation

@ZnPdCo
Copy link
Copy Markdown
Contributor

@ZnPdCo ZnPdCo commented Feb 2, 2026

修复 #281 中的 int 存空间问题(显示为负数),以及 Windows 下判定空间用 int 或 unsigned int 的问题(无法开 > 2GB 的空间)

注意,#281 的问题还没有完全修复。

本地使用 Windows 测试下面的代码:

#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<int> c(535350912);
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
    return 0;
}
image

(不知道为什么过了一个月再测这段代码就超空间了,动态调整一下 c 的 size 应该能行)

@ZnPdCo ZnPdCo marked this pull request as draft February 2, 2026 13:34
@ZnPdCo ZnPdCo marked this pull request as ready for review February 3, 2026 06:33
@ZnPdCo ZnPdCo marked this pull request as draft February 4, 2026 02:11
Comment thread src/component/exportutil/exportutil.cpp Outdated
@ZnPdCo
Copy link
Copy Markdown
Contributor Author

ZnPdCo commented Feb 9, 2026

if (memoryLimit != -1) {
GetProcessMemoryInfo(pi.hProcess, (PROCESS_MEMORY_COUNTERS *)&memoryInfo, sizeof(memoryInfo));
if (qMax(memoryInfo.PrivateUsage, memoryInfo.PeakWorkingSetSize) > memoryLimit * 1024 * 1024) {
TerminateProcess(pi.hProcess, 0);
score = 0;
result = MemoryLimitExceeded;
memoryUsed = timeUsed = -1;
return;
}
}
bool isProgramFinishedInExtraTimeLimit = false;
QElapsedTimer timer;
timer.start();
while (timer.elapsed() <= timeLimit + extraTime) {
if (WaitForSingleObject(pi.hProcess, 0) == WAIT_OBJECT_0) {
isProgramFinishedInExtraTimeLimit = true;
break;
}
if (memoryLimit != -1) {
GetProcessMemoryInfo(pi.hProcess, (PROCESS_MEMORY_COUNTERS *)&memoryInfo, sizeof(memoryInfo));
if (qMax(memoryInfo.PrivateUsage, memoryInfo.PeakWorkingSetSize) > memoryLimit * 1024U * 1024) {
TerminateProcess(pi.hProcess, 0);
score = 0;
result = MemoryLimitExceeded;
memoryUsed = timeUsed = -1;
return;
}
}
QCoreApplication::processEvents();
if (stopJudging || skipEnabled) {
TerminateProcess(pi.hProcess, 0);
if (skipEnabled) {
score = 0;
result = TimeLimitExceeded;
timeUsed = memoryUsed = -1;
}
return;
}
QThread::msleep(10);
}

这里怎么把同样的逻辑写了两遍

@alphagocc
Copy link
Copy Markdown
Member

if (memoryLimit != -1) {
GetProcessMemoryInfo(pi.hProcess, (PROCESS_MEMORY_COUNTERS *)&memoryInfo, sizeof(memoryInfo));
if (qMax(memoryInfo.PrivateUsage, memoryInfo.PeakWorkingSetSize) > memoryLimit * 1024 * 1024) {
TerminateProcess(pi.hProcess, 0);
score = 0;
result = MemoryLimitExceeded;
memoryUsed = timeUsed = -1;
return;
}
}
bool isProgramFinishedInExtraTimeLimit = false;
QElapsedTimer timer;
timer.start();
while (timer.elapsed() <= timeLimit + extraTime) {
if (WaitForSingleObject(pi.hProcess, 0) == WAIT_OBJECT_0) {
isProgramFinishedInExtraTimeLimit = true;
break;
}
if (memoryLimit != -1) {
GetProcessMemoryInfo(pi.hProcess, (PROCESS_MEMORY_COUNTERS *)&memoryInfo, sizeof(memoryInfo));
if (qMax(memoryInfo.PrivateUsage, memoryInfo.PeakWorkingSetSize) > memoryLimit * 1024U * 1024) {
TerminateProcess(pi.hProcess, 0);
score = 0;
result = MemoryLimitExceeded;
memoryUsed = timeUsed = -1;
return;
}
}
QCoreApplication::processEvents();
if (stopJudging || skipEnabled) {
TerminateProcess(pi.hProcess, 0);
if (skipEnabled) {
score = 0;
result = TimeLimitExceeded;
timeUsed = memoryUsed = -1;
}
return;
}
QThread::msleep(10);
}

这里怎么把同样的逻辑写了两遍

不知道,古早代码,感觉可以优化掉

@ZnPdCo
Copy link
Copy Markdown
Contributor Author

ZnPdCo commented Feb 21, 2026

修复这个 bug 可能需要进行其他修改,我会拆成多个 pr 进行修改。

@ZnPdCo ZnPdCo marked this pull request as ready for review March 22, 2026 01:37
@ZnPdCo ZnPdCo marked this pull request as draft March 22, 2026 01:41
@ZnPdCo ZnPdCo marked this pull request as ready for review March 22, 2026 01:54
@ZnPdCo ZnPdCo requested a review from CoelacanthusHex March 22, 2026 01:55
Comment thread src/core/processrunner_win.cpp
Comment thread src/core/processrunner_win.cpp
Comment thread src/core/taskjudger.h Outdated
Comment thread src/core/contestant.cpp Outdated
@alphagocc alphagocc merged commit 2e89fbf into Project-LemonLime:master Apr 9, 2026
19 checks passed
Comment thread src/core/contestant.cpp
in >> timeUsed;
in >> memoryUsed;
// memoryUsed 之前存储为 int 三维数组,现在改为了 qint64,因此先读取旧结构,再逐层转换
QList<QList<QList<int>>> oldMemoryUsed;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我是不是忘记 memoryUsed.clear(); 了😂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

开了一个新的 #299

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants