zoukankan      html  css  js  c++  java
  • 内存对齐

    32位CPU则往四个字节凑。所以创建结构体等类型时要注意内存对齐的原则书写,以免编译器申请不必要的内存。

    typedef struct udp_data
    {
        double d;  8
        char a;    4
        double b;  8
    } UDP_PACKET;

    typedef struct udp_data
    {
        char d;    1
        char a;    3
        double b;  8
    } UDP_PACKET;

    typedef struct udp_data
    {
        char d;    1
        char a;    3
        int b;     4
    } UDP_PACKET;

    typedef struct udp_data  
    {
        double d;  8
        char a;    4
        int b;     4
    } UDP_PACKET;

    typedef struct udp_data  浪费内存
    {
        char a;    4   ---》 char a;    1
        int b;     4   ---》 char c;    3
        char c;    4   ---》 int b;     4
        double d;  8   ---》 double d;  8
    } UDP_PACKET;


    /***************************************/
    #include <stdio.h>
    #include <string.h>

    #define UDP_PACKET_DATA 1024

    typedef struct udp_data
    {
        char a;
        int b;
        char c;
        double d;
    } UDP_PACKET;

    int main()
    {
        UDP_PACKET pack;
        printf("udp_data size:%d ", sizeof(pack));
        printf("a:%p  b:%p ", &pack.a, &pack.b);
        printf("b:%p  c:%p ", &pack.b, &pack.c);
        printf("c:%p  d:%p ", &pack.c, &pack.d);
    }

  • 相关阅读:
    稠密光流
    分水岭分割
    Haar小波分析
    内积空间
    矩阵LU分解
    opencv笔记---contours
    Deformable Templates For Eye Detection
    最小二乘法
    字符集及编码
    层次聚类
  • 原文地址:https://www.cnblogs.com/kaijia9/p/3394950.html
Copyright © 2011-2022 走看看