zoukankan      html  css  js  c++  java
  • 简易内存信息打印

    调试时经常需要看内存中的一些数据,dump_mem能比较方打印出内存情况。

     1 void dump_mem(void *data, int len)
     2 {
     3     unsigned char *p;
     4     int i, n;
     5 
     6     p = data;
     7 
     8     printf("  Address                Bytes                 Characters\n");
     9     printf(" --------    ------------------------------    ----------\n");
    10     for (n = 0; n < len; n++){
    11         printf(" %.8X    ", (unsigned int)p);
    12         for (i = 0; i < 10; i++)
    13             printf("%.2X ", *(p + i));
    14         printf("    ");
    15         for (i = 0; i < 10; i++){
    16             unsigned char ch = *(p + i);
    17             if (!isprint(ch))
    18                 ch = '.';
    19             printf("%c", ch);
    20         }
    21         printf("\n");
    22         p += 10;
    23     }
    24 }

    打印出来的样式

     1   Address                Bytes                 Characters
     2  --------    ------------------------------    ----------
     3  00750F40    01 00 00 00 40 00 00 00 02 00     ....@.....
     4  00750F4A    00 00 00 00 00 00 00 00 00 00     ..........
     5  00750F54    00 00 00 00 00 00 00 00 00 00     ..........
     6  00750F5E    00 00 00 00 00 00 00 00 00 00     ..........
     7  00750F68    00 00 00 00 00 00 00 00 00 00     ..........
     8  00750F72    00 00 00 00 00 00 00 00 00 00     ..........
     9  00750F7C    00 00 00 00 00 00 00 00 00 00     ..........
    10  00750F86    00 00 00 00 00 00 00 00 00 00     ..........
    11  00750F90    00 00 00 00 00 00 00 00 00 00     ..........
    12  00750F9A    00 00 00 00 00 00 00 00 00 00     ..........
  • 相关阅读:
    Oracle与MySQL的几点区别
    MySQL使用Union创建视图报错
    MySQL指定mysqld启动时所加载的配置文件
    MySQL使用位运算
    django rest framework(3)
    Django Rest Framework(2)
    Django 之缓存
    RESTful API
    restful framework 认证源码流程
    其他排序
  • 原文地址:https://www.cnblogs.com/gleam/p/3051194.html
Copyright © 2011-2022 走看看