我为内存泄漏压力开发了一个小应用程序:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int period = 0;
int size = 40000001;
char *buf = NULL;
if (argc > 1) period = atoi(argv[1]);
if (period == 0) period = 21;
for (;;) {
buf = malloc(size);
if (buf == NULL) printf ("malloc return NULL\n");
sleep(period);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
应用程序每20秒进行一次~40M的内存分配(无空闲).我的系统内存是~256M.
我使用top命令检查了压力应用程序消耗的内存:
$top | grep "stress"
873 5689 root S 39892 16% 0% ./stress_test
873 5689 root S 39892 16% 0% ./stress_test
873 5689 …Run Code Online (Sandbox Code Playgroud) 我有以下文件
aaa1.bbb1.ccc toto
aaa1.bbb1.ddd. titi
aaa2.bbb2.ccc
aaa2.bbb2.eee tza
aaa2.bbb2.ddd.
Run Code Online (Sandbox Code Playgroud)
我想在每行的开头添加一个字符串.如果该行的第一个字段完成,则该字符串将为"OK",如果该行的第一个字段未完成,则.该字符串将为"NOK".
田野的分界是空间
所以基于上面的例子,命令的输出将是:
NOK aaa1.bbb1.ccc toto
OK aaa1.bbb1.ddd. titi
NOK aaa2.bbb2.ccc
NOK aaa2.bbb2.eee aza
OK aaa2.bbb2.ddd.
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做?
我有一个h1.h包含以下变量声明的头文件:
h1.h
struct namespaces
{
char *soap_env;
char *soap_enc;
char *xsd;
char *xsi;
} ns;
Run Code Online (Sandbox Code Playgroud)
我包括头文件h1.h在2个C文件c1.c和c2.c.
c1.c
#include "h1.h"
Run Code Online (Sandbox Code Playgroud)
c2.c
#include "h1.h"
Run Code Online (Sandbox Code Playgroud)
我希望在构建中出错,但我没有.在构建中没有错误也没有警告.
这是正常的吗?
在程序运行时,此类问题是否会导致未定义的行为?
我有这样一个文件:
aaa.bbb.1.ccc
xxx.bbb.21
mmm.ppp
xxx.eee
mmm.qqqq
xxx.hhh.12.ddd
Run Code Online (Sandbox Code Playgroud)
我想移动开始与所有线路xxx.在文件的顶部用一个简单的命令(使用sed,awk,grep...).
所以我的新文件将如下所示:
xxx.bbb.21
xxx.eee
xxx.hhh.12.ddd
aaa.bbb.1.ccc
mmm.ppp
mmm.qqqq
Run Code Online (Sandbox Code Playgroud)
这该怎么做?
当我在类中重载 cout 运算符时出现编译错误
我缺少什么?
下面是源代码。当我在类外定义重载运算符时,问题就消失了
#include <iostream>
using namespace std;
class Box {
public:
int l, b, h;
Box(int length, int breadth, int height) : l(length), b(breadth), h(height) {}
#if 1
ostream& operator<<(ostream& os) {
os << (l * b * h);
return os;
}
#endif
};
#if 0
ostream& operator<<(ostream& os, Box inb) {
os << (inb.l * inb.b * inb.h);
return os;
}
#endif
int main(void) {
Box B(3,4,5);
cout << B << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个用diff命令生成的补丁:
diff -ruN orig/ new/ > file.patch
Run Code Online (Sandbox Code Playgroud)
我想使用svn实用程序将此补丁应用于svn repo。怎么做?
我有以下代码.我想完成汇编代码,如下所示:
int main(void)
{
int x = 10;
int i=0;
label1:
asm (.....) // code to add here: if i>=x then jump to label2
printf("%d\n",i);
i++;
asm (.....) // code to add here: jump to label 1
label2:
printf("out\n");
}
Run Code Online (Sandbox Code Playgroud)
我的机器是x86,操作系统是Ubuntu 12
以下代码
int i=0;
while(i<10) {
printf("%d\n", i++);
}
Run Code Online (Sandbox Code Playgroud)
相当于
int i=0;
while(i<10) {
printf("%d\n", i); i++;
}
Run Code Online (Sandbox Code Playgroud)
但是下面的代码
int i=0;
while(i<10) {
printf("%d\n", i+=2);
}
Run Code Online (Sandbox Code Playgroud)
相当于
int i=0;
while(i<10) {
i+=2; printf("%d\n", i);
}
Run Code Online (Sandbox Code Playgroud)
如何使它等同于
int i=0;
while(i<10) {
printf("%d\n", i); i+=2;
}
Run Code Online (Sandbox Code Playgroud)
同样的 i++
int main(void)
{
int a=5;
fun();
printf("%d",a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我需要编写函数fun(),以便printf将打印15.我不能改变fun()的原型,即它不能传递任何东西,我不能修改main()函数中的任何东西