What is the purpose of LongLength for .Net Arrays?

后端 未结 4 1265
轮回少年
轮回少年 2021-01-13 08:40

What is the purpose of the LongLength property for arrays in .Net. Using a standard integer for length, you could accommodate up to 2 billion indices. Are there really peo

4条回答
  •  花落未央
    2021-01-13 09:43

    There's a school of thought known as the "0, 1 or N" school which believes that you should have either none of something; one of something; or any number of something, as resources permit.

    In other words, don't set arbitrary limits if you don't have to. Arbitrary limits have given us such monstrosities as:

    • the 640K limit in early PCs.
    • buffer overflow vulnerabilities.
    • the hideous CHS disk addressing scheme.

    Keep in mind that even two billion 64-bit integers only takes up

                17,179,869,184 bytes of the
    18,446,744,073,709,551,616 bytes of 64-bit address space available.
    

    That's less than 1 thousand-millionth, or 10-9, or you could have many millions of these massive arrays before running out of address space.

提交回复
热议问题