search

Home  >  Q&A  >  body text

linux 32和64 在2g内存运行中有什么影响

linux 32和64 在2g内存运行中有什么影响

巴扎黑巴扎黑2783 days ago713

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 13:25:45

    According to the memory management mechanism of Linux, a 64-bit system takes up 50% more memory than a 32-bit system. Under the premise of 2G RAM, there is no other difference. Therefore, under this premise, it is best to install 32-bit system. Bit system, this can free up more memory to avoid premature use of swap partitions, resulting in a large number of I/O operations that reduce performance.

    64-bit programs always take up more memory than 32-bit programs, for the following reasons:
    1. 64-bit pointers need to allocate more memory space (exactly double, this is hard)
    2. In a 64-bit environment, struct alignment in memory requires more space. The worst margin is exactly 100% more memory than 32-bit (see example 1 below). Of course, it is rare. Today’s compilers and CPUs The instructions have been optimized well.
    3. A 64-bit stack requires more space than a 32-bit stack
    4. Also, no more expansion.

    For example, you will understand:

    cstruct MyStruct1
    {
       char m_c;
       void *m_p;
       int m_i;
    };
    

    This struct is 12 bytes in 32-bit and 24 bytes in 64-bit.
    Another example:

    cstruct MyStruct2
    {
       void *m_p;
       int m_i;
       char m_c;
    };
    

    This struct is also 12 bytes in 32-bit environment, but 16 bytes in 64-bit environment.
    The image comparison of these two structs in memory is as follows:

    The picture is a comparison under Windows, and the same is true for Linux. After all, the memory is the same. I said 50% more is an average estimate. If it is not optimized during compilation, it may be 100% more.

    reply
    0
  • Cancelreply