哪一个需要更少的内存? [英] which one requires less memory?
问题描述
由于我们不想在计算字节数时出错,我们使用
代码
char * p;
...
p = malloc(strlen(" hello")+ 1);
strcpy(p," hello");
而不是预期的
char * p;
...
p = malloc( 6);
strcpy(p," hello");
i想要比较每个版本的内存要求:哪一个
需要更少的记忆?
Since we did not want to make an error in counting of bytes, we used
the code
char *p;
...
p = malloc(strlen("hello")+1);
strcpy(p,"hello");
instead of the intended
char *p;
...
p = malloc(6);
strcpy(p,"hello");
i want to compare the memory requirements of each version: which one
requires less memory?
推荐答案
khan写道:
khan wrote:
既然我们做了我不想在计算字节数时出错,我们使用
代码
char * p;
...
p = malloc(strlen(" hello")+ 1);
strcpy(p," hello");
而不是预期的
char * p;
...
p = malloc(6);
strcpy(p," hello& ;);
i想要比较每个版本的内存要求:哪一个
需要更少的内存?
Since we did not want to make an error in counting of bytes, we used
the code
char *p;
...
p = malloc(strlen("hello")+1);
strcpy(p,"hello");
instead of the intended
char *p;
...
p = malloc(6);
strcpy(p,"hello");
i want to compare the memory requirements of each version: which one
requires less memory?
您是否比较strlen(hello)+ 1到6?
-
Ian Collins。
Did you compare strlen("hello")+1 to 6?
--
Ian Collins.
是..
两者的评价都是6 ...但是这两个程序内部是否使用相同的内存?<
内存量? br />
Yes..
Both evaluates to 6 ...but does these two programs internally use same
amount of memory?
khan写道:
khan wrote:
是..
两者评估到6 ...但这两个程序内部使用相同的内存吗?
Yes..
Both evaluates to 6 ...but does these two programs internally use same
amount of memory?
请保留足够的上下文感觉。
当然他们这样做,他们都是malloc(6)。
-
伊恩柯林斯。
Please retain enough context for your post to make sense.
Of course they do, they a both malloc(6).
--
Ian Collins.
这篇关于哪一个需要更少的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!