Skip to content

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

Open
ZnPdCo wants to merge 11 commits intoProject-LemonLime:masterfrom
ZnPdCo:int64-for-used-memory
Open

fix: store memoryUsed as long long instead of int#292
ZnPdCo wants to merge 11 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
@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

if (qMax(memoryInfo.PrivateUsage, memoryInfo.PeakWorkingSetSize) >
config.memoryLimit * 1024U * 1024) {
1ll * config.memoryLimit * 1024 * 1024) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

不如把 config.memoryLimit 一起改成 i64

Copy link
Copy Markdown
Contributor Author

@ZnPdCo ZnPdCo Mar 23, 2026

Choose a reason for hiding this comment

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

这个改动量是不是稍微有些大了,不是很想去改,要改也另开一个 pr 去改吧

int kernelTimeUsed = realKernelTime.wMilliseconds + realKernelTime.wSecond * 1000 +
realKernelTime.wMinute * 60 * 1000 + realKernelTime.wHour * 60 * 60 * 1000;
GetProcessMemoryInfo(pi.hProcess, (PROCESS_MEMORY_COUNTERS *)&memoryInfo, sizeof(memoryInfo));
res.memoryUsed = memoryInfo.PeakWorkingSetSize;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这边还是int

void judgingStarted(QString);
void judgingFinished();
void dialogAlert(QString);
void singleCaseFinished(QString, int, int, int, int, int, int, int);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这里还是 int

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这边往上的信号应该也还是 int 没改

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