Q,1计数和内存使用情况 [英] Q, 1 counting and memory usage
问题描述
嗨我问两个问题......有人可以告诉我
i一个linux gcc用户,想知道
- 我的c代码使用了多少物理内存?
和另一个是
- 我需要一个(标准)函数来例如,计算''1'的数量
,
1010 1000 0000 0000 ====> 3
0000 0000 1111 0000 ====> 4
hi i ask two questions......someone can tell me
i an a linux gcc user and wanna know that
- how much physical memory is used for my c code ?
and another one is
- i need a (standard) function to count the number of ''1''
for example,
1010 1000 0000 0000 ====> 3
0000 0000 1111 0000 ====> 4
推荐答案
" Hur" < JA ********** @ yahoo.com>在留言中写道
新闻:ct ********** @ delphi.et.tudelft.nl ...
"Hur" <ja**********@yahoo.com> wrote in message
news:ct**********@delphi.et.tudelft.nl...
嗨我问两个问题.. ....有人可以告诉我
我是一个linux gcc用户,想知道
- 我的c代码使用了多少物理内存?
取决于该计划。没有你的C代码,你的编译器,那个编译器的设置就是b / b $ b,根本不可能告诉你。例如,gcc -O3将产生与gcc -Os不同的数字
,结果将是不同的,具体取决于i386和Atmel AVR。
- 我需要一个(标准)函数来计算1的数量,例如,
1010 1000 0000 0000 ====> 3
0000 0000 1111 0000 ====> 4
hi i ask two questions......someone can tell me
i an a linux gcc user and wanna know that
- how much physical memory is used for my c code ?
Depends on the program. Without you C-code, your compiler, the setting of
that compiler, it is simply impossible to tell. gcc -O3 will produce a
different number than gcc -Os, for instance, and the results will be
different depending for an i386 and an Atmel AVR.
- i need a (standard) function to count the number of ''1''
for example,
1010 1000 0000 0000 ====> 3
0000 0000 1111 0000 ====> 4
这并不难。
int count_ones(int value)
{
int cnt = 0;
while(value!= 0)
{
if(0!=(cnt& 1))
cnt ++;
value>> = 1;
}
返回cnt;
}
That''s not hard.
int count_ones(int value)
{
int cnt = 0;
while(value != 0)
{
if (0 != (cnt & 1))
cnt++;
value >>= 1;
}
return cnt;
}
蒲公英写道:
Hur < JA ********** @ yahoo.com>在消息中写道
新闻:ct ********** @ delphi.et.tudelft.nl ...
"Hur" <ja**********@yahoo.com> wrote in message
news:ct**********@delphi.et.tudelft.nl...
- 我需要一个(标准)函数来计算''1'的数量
例如,
1010 1000 0000 0000 ====> 3
0000 0000 1111 0000 ====> 4
- i need a (standard) function to count the number of ''1''
for example,
1010 1000 0000 0000 ====> 3
0000 0000 1111 0000 ====> 4
这并不难。
int count_ones(int value)
{
int cnt = 0;
while(value!= 0)
{
if(0!=(cnt& 1))
cnt ++;
value>> = 1;
}
返回cnt;
}
That''s not hard.
int count_ones(int value)
{
int cnt = 0;
while(value != 0)
{
if (0 != (cnt & 1))
cnt++;
value >>= 1;
}
return cnt;
}
它比看起来更难。 />
printf("%d \ n",count_ones(-1));
在具有符号位传播的系统上,此调用可以需要一些时间。
考虑unsigned long的优点。
It''s harder than it looks.
printf("%d\n", count_ones(-1));
On systems with sign bit propagation, this call could take some time.
Consider the merits of unsigned long.
" infobahn" <在****** @ btinternet.com>在消息中写道
news:42 *************** @ btinternet.com ...
"infobahn" <in******@btinternet.com> wrote in message
news:42***************@btinternet.com...
dandelion写道:
dandelion wrote:
Hur < JA ********** @ yahoo.com>在消息中写道
新闻:ct ********** @ delphi.et.tudelft.nl ...
"Hur" <ja**********@yahoo.com> wrote in message
news:ct**********@delphi.et.tudelft.nl...
- 我需要一个(标准)函数来计算''1'的数量
例如,
1010 1000 0000 0000 ====> 3
0000 0000 1111 0000 ====> 4
- i need a (standard) function to count the number of ''1''
for example,
1010 1000 0000 0000 ====> 3
0000 0000 1111 0000 ====> 4
这并不难。
int count_ones(int value)
{
int cnt = 0;
while(value!= 0)
{
if(0!=(cnt& 1))
cnt ++;
value>> = 1;
}
返回cnt;
}
That''s not hard.
int count_ones(int value)
{
int cnt = 0;
while(value != 0)
{
if (0 != (cnt & 1))
cnt++;
value >>= 1;
}
return cnt;
}
它比看起来更难。
printf("%d \ n",count_ones(-1));
在具有符号位传播的系统上,此调用可能需要一些时间。
考虑unsigned long的优点。
It''s harder than it looks.
printf("%d\n", count_ones(-1));
On systems with sign bit propagation, this call could take some time.
Consider the merits of unsigned long.
屎,scheisse,merd''allors,kut遇见peren! Gretverdrie! ;-)
绝对正确,当然。永远不要低估这个问题。应该
确实是一个unsigned int / long。
Shit, scheisse, merd''allors, kut met peren! Gretverdrie! ;-)
Absolutely right, of course. Never underestimate the problem. That should
indeed have been an unsigned int/long.
这篇关于Q,1计数和内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!