Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of insufficient memory in large array stack in C++

Shulou Source: shulou.com Published: 2022-05-31 22:11:51 10月02日 Update

This article mainly introduces the relevant knowledge of "how to solve the problem of insufficient memory in large array stack in C++". The editor shows you the process of operation through an actual case. I hope that this article "how to solve the problem of insufficient memory in large array stack in C++" can help you solve the problem.

In C++, we can create an array directly by:

Const int N = 6countries Const int Nx = 100th Const int Ny = 100th double phi [N] [Nx] [Ny]; double phi_ b [N] [Nx] [Ny]

However, if the above Nx and Ny are relatively small, once the Nx and Ny are very large, an error will be reported, resulting in compilation failure.

To solve this problem, we can use the following methods to solve this problem:

1. Open the stack a little larger in the link tab in VC's Project setting (4m by default in windows)

2. Declared as global or static, these two variables do not press the stack and can be opened as much as you want. Obviously, the global variable itself can have more memory (this method can be effective immediately, or good).

3. Use the method of dynamically allocating array memory:

Int * A = new int [90000]; .delete A

4. Use vector as follows:

# include using namespace std;void main () {vector A (90000); A [0] = 1;} that's all for "how to solve the problem of insufficient memory in large array stacks in C++". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Problems memory arrays methods not enough Centrals knowledge variables more industry facets different good practical large global content dynamic practical practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi MariaDB macOS Shulou Technology