Why is 248x248 the maximum bi dimensional array size I can declare?

后端 未结 3 1622
难免孤独
难免孤独 2020-12-02 00:48

I have a program problem for which I would like to declare a 256x256 array in C. Unfortunately, I each time I try to even declare an array of that size (integers) and I run

3条回答
  •  生来不讨喜
    2020-12-02 01:22

    There are three places where you can allocate an array in C:

    • In the automatic memory (commonly referred to as "on the stack")
    • In the dynamic memory (malloc/free), or
    • In the static memory (static keyword / global space).

    Only the automatic memory has somewhat severe constraints on the amount of allocation (that is, in addition to the limits set by the operating system); dynamic and static allocations could potentially grab nearly as much space as is made available to your process by the operating system.

    The simplest way to see if this is the case is to move the declaration outside your function. This would move your array to static memory. If crashes continue, they have nothing to do with the size of your array.

提交回复
热议问题