显示内存状态示例分享
发布时间:2017-01-07 来源:查字典编辑
摘要:复制代码代码如下:#includevoidmemstat(void*memory,size_tmemsize){printf("------...
复制代码 代码如下:
#include <stdio.h>
void memstat(void *memory, size_t memsize) {
printf("-------memory------ ----n");
for(int i=0; i<memsize; i++) {
char *p = (char*) memory;
printf("%d%d%d%d "
, 0x1 & p[i] >> 3
, 0x1 & p[i] >> 2
, 0x1 & p[i] >> 1
, 0x1 & p[i]);
if(i % 4 == 3) {
#define FILTER(c) ((c)<' '? '.': (c))
printf("%c%c%c%c"
, FILTER(p[i-3])
, FILTER(p[i-2])
, FILTER(p[i-1])
, FILTER(p[i]));
puts("");
}
}
printf("------------------- ----n");
}
int main(int argc, char **argv) {
int memory[8];
memset(memory, -1, sizeof(memory));
memory[0] = 3;
memory[2] = 0xAAAAAAAA;
memory[3] = 0;
strcpy((char *)&memory[4], "= = . ");
memstat(memory, sizeof(memory));
}