以下c代码行创建一个数组来存储来自摄像头的图片。图像大约是22kb。
32*1024
mcu是32位。我只是想知道为什么它是package com.mateoj.multiactivitydrawer;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
public class near extends BaseActivity {
ListView list;
String[] itemname ={
"S. Raj Tailors",
"Bangalore Iyengar Bakery",
"Renuka Photo Studio",
"Huddar Xerox",
"Maruti Xerox",
"Image Copy & Print Center",
"Sri Mallikarjun Medical",
"Jyotinling Store",
"Shabir Anna General Store",
"Rohit General Store",
"Bala Shopping",
"Nisarga Hotel",
"Hotel Indian",
"Netravati Hotel",
"Chans Garden Hotel"
};
String[] itemdesc = {
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : ",
"Contact : "
};
Integer[] imgid={
R.drawable.tailor,
R.drawable.bangiy,
R.drawable.renukap,
R.drawable.hudarx,
R.drawable.marutix,
R.drawable.imagex,
R.drawable.medical,
R.drawable.jyotis,
R.drawable.shabir,
R.drawable.stat,
R.drawable.stat2,
R.drawable.nisargh,
R.drawable.hotelind,
R.drawable.netra,
R.drawable.placement
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.near_layout);
CustomListNearAdapter adapter=new CustomListNearAdapter(this, itemname, imgid,itemdesc);
ListView listView = (ListView) findViewById(R.id.list_li);
listView.setAdapter(adapter);
}
@Override
protected boolean useDrawerToggle() {
return false;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_gallery)
return true;
if (item.getItemId() == android.R.id.home)
onBackPressed();
return super.onOptionsItemSelected(item);
}
}
?是32因为它是32位吗?为什么会是1024?
谢谢
答案 0 :(得分:3)
因为它需要32千字节的内存。一千字节是1024字节,32*1024
是32千字节。
答案 1 :(得分:1)
尝试编写自我记录代码。 32 * 1024
提示“给我32kb”。它比32768
更清晰,这只是一个奇怪的“神奇数字”,没有给出任何解释。
(但显然不够清楚,或者你不会问这个问题。)
更清晰的方式来写同样的东西会是这样的:
#define SIZE_32KB (32u * 1024u)
...
uint8_t picturearray [SIZE_32KB];
或者
#define SIZE_KB 1024u
...
uint8_t picturearray [32u * SIZE_KB];
注意:在8/16位系统上,32 * 1024
将是一个严重的错误!它会给出整数溢出和未定义的行为。对上面的整数常量使用u
后缀,以使代码可移植。