Comments (12)
你是通过malloc分配的空间么?貌似只malloc而不去memset的话就不会被计算在内。
你可以贴一下测试的代码。
from judger.
不太明白您说的malloc和memset是指哪里
我是通过设置的preexec_fn来限制的内存
class Limiter:
def init(self, cpu, mem):
self.cpu = cpu
self.mem = mem
self.cpu_time = self.memory_use = 0
def __call__(self):
res.setrlimit(res.RLIMIT_CORE, (0, 0))
res.setrlimit(res.RLIMIT_MEMLOCK, (0, 0))
res.setrlimit(res.RLIMIT_FSIZE, (Tester.OUTPUT_MAX, Tester.OUTPUT_MAX))
res.setrlimit(res.RLIMIT_CPU,(self.cpu,self.cpu))
if self.mem != -1:
res.setrlimit(res.RLIMIT_AS,(self.mem,self.mem))
os.nice(10)
def cxx(self):
ofile = TemporaryFile('w+t')
if self.ua:
bin = ANSWER_PATH + self.id + '/x' + self.id
else:
bin = BINARY_PATH + self.id + '/x' + self.id
p = Popen(bin, stdin=self.ifile, stdout=ofile, preexec_fn=Tester.Limiter(self.lcpu, self.lmem),
universal_newlines=True, stderr=DEVNULL)
waitResult = os.wait4(p.pid,0)
print(waitResult)
self.return_code = waitResult[1]
在 2016-03-20 10:38:17,"李扬" [email protected] 写道:
你是通过malloc分配的空间么?貌似只malloc而不去memset的话就不会被计算在内。
你可以贴一下测试的代码。
—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
from judger.
你上面说的
然而就算这个ru_maxrss无论我怎样修改测试cpp代码,数值都是类似的,貌似就是给出的空间而非使用的空间
你可以贴一下测试用的几个cpp代码
from judger.
#include<iostream>
using namespace std;
int a,b,c[100000000];
int main()
{
cin>>a>>b;
for(int i=1;i<5*1e7;i++);
cout<<a+b<<endl;
}
您的意思是不是c数组需要一些操作才能检测到内存?
在 2016-03-20 10:45:24,"李扬" [email protected] 写道:
你上面说的
然而就算这个ru_maxrss无论我怎样修改测试cpp代码,数值都是类似的,貌似就是给出的空间而非使用的空间
你可以贴一下测试用的几个cpp代码
—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
from judger.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
// 1k
int small_size = 1024;
// 150m
int big_size = 150 * 1024 * 1024;
int *s = NULL, *b = NULL;
s = (int *)malloc(small_size);
if(s){
memset(s, 0, small_size);
printf("malloc small size succedeed\n");
}
else{
printf("malloc small size failed\n");
return -1;
}
b = (int *)malloc(big_size);
if(b){
memset(b, 0, big_size);
printf("malloc big size succedeed\n");
}
else{
printf("malloc big size failed\n");
return -2;
}
return 0;
}
你把这个分成两部分,一个small,一个big的,看看有区别么?
update:
- 经过测试,如果不memset,内存确实不会被计算在内的;
from judger.
你的代码的问题可能是数组c没有使用,被编译器优化掉了。
from judger.
分成两份运行以后……在linux虚拟机上返回的结果还是一样的
(16508, 0, resource.struct_rusage(ru_utime=0.0, ru_stime=0.0, ru_maxrss=5268, ru_ixrss=0, ru_idrss=0, ru_isrss=0, ru_minflt=478, ru_majflt=0, ru_nswap=0, ru_inblock=0, ru_oublock=8, ru_msgsnd=0, ru_msgrcv=0, ru_nsignals=0, ru_nvcsw=1, ru_nivcsw=2))
malloc big size succedeed 3
Result is -7
(16509, 0, resource.struct_rusage(ru_utime=0.0, ru_stime=0.0, ru_maxrss=5280, ru_ixrss=0, ru_idrss=0, ru_isrss=0, ru_minflt=485, ru_majflt=0, ru_nswap=0, ru_inblock=0, ru_oublock=8, ru_msgsnd=0, ru_msgrcv=0, ru_nsignals=0, ru_nvcsw=1, ru_nivcsw=2))
malloc small size succedeed 3
Result is -7
在 2016-03-20 10:58:59,"李扬" [email protected] 写道:
你的代码的问题可能是数组c没有使用,被编译器优化掉了。
—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
from judger.
也换到了服务器上,刚刚那份代码的数组使用了,那份big的也添加了,仍旧是与helloworld返回内存相差无几,但耗时都是准确的
在 2016-03-20 10:58:59,"李扬" [email protected] 写道:
你的代码的问题可能是数组c没有使用,被编译器优化掉了。
—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
from judger.
我上面补充了一下,你看到的有没有memset
from judger.
添加了memset以后所有的代码都跟预期一样了,太感谢了!
就是不知道为什么for循环赋值的那种没有修改内存很明显
from judger.
我又看了下你的代码。。
你for循环后面多了一个分号。。
from judger.
哦哦那个是我跑耗时的……不管怎么说真的非常感谢!
from judger.
Related Issues (20)
- Judger的文档网站挂了 HOT 1
- M1 无法正常运行沙盒 HOT 4
- 运行demo时,result=4,请问大佬有解决办法么? HOT 2
- 你好,这个 OJ 要怎么用? HOT 1
- 有没有办法可以给远程进程安装seccomp-filter? HOT 2
- Tip: use native executable with Java JNI
- Wrong Answer because of last blank in the printf HOT 2
- 一个用go调用judger.so的第三方库
- Run judger on alpine linux container (for cloud environments) HOT 3
- Question: Do we really need root user privileges to run this Judger?
- 对于 python 文件运行,有没有对应的规则程序,现在使用c_cpp会报"signal": 31
- 关于rusage的值
- 如果你正在被设置seccomp所困扰 HOT 1
- libseccomp seems to be not working as expected
- 编译报错 HOT 3
- Problem while building module in nodejs HOT 3
- Import pandas, scipy, numpy
- Arm64 需要额外的系统调用 HOT 1
- Stack Trace is missing for Result- 4 [Runtime Error] for C and CPP languages HOT 1
- go 语言沙箱编译资源报错
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from judger.