How to Increase Error Limit in Visual Studio

Is it possible to change VS Code's error message length?

It turned out that it's not editor specific but you can achieve this by setting "noErrorTruncation": true, in your tsconfing.json file.

Memory error at lower limit than expected when implementing Sieve of Eratosthenes in C++

Turning the comment into a full answer:

Your operating system reserves a special section in the memory to represent the call stack of your program. Each function call pushes a new stack frame onto the stack. If the function returns, the stack frame is removed from the stack. The stack frame includes the memory for the parameters to your function and the local variables of the function. The remaining memory is referred to as the heap. On the heap, arbitrary memory allocations can be made, whereas the structure of the stack is governed by the control flow of your program. A limited amount of memory is reserved for the stack, when it gets full (e.g. due to too many nested function calls or due to too large local objects), you get a stack overflow. For this reason, large objects should be allocated on the heap.

General references on stack/heap: Link, Link

To allocate memory on the heap in C++, you can:

  • Use vector<bool> is_idx_prime(target);, which internally does a heap allocation and deallocates the memory for you when the vector goes out of scope. This is the most convenient way.

  • Use a smart pointer to manage the allocation: auto is_idx_prime = std::make_unique<bool[]>(target); This will also automatically deallocate the memory when the array goes out of scope.

  • Allocate the memory manually. I am mentioning this only for educational purposes. As mentioned by Paul in the comments, doing a manual memory allocation is generally not advisable, because you have to manually deallocate the memory again. If you have a large program with many memory allocations, inevitably you will forget to free some allocation, creating a memory leak. When you have a long-running program, such as a system service, creating repeated memory leaks will eventually fill up the entire memory (and speaking from personal experience, this absolutely does happen in practice). But in theory, if you would want to make a manual memory allocation, you would use bool *is_idx_prime = new bool[target]; and then later deallocate again with delete [] is_idx_prime.

Is there a cleaner way to handle compiler errors C1076 and C3859?

The /Zm parameter does not change anything about how the code is interpreted, so it does not hide a problem in the code, other than the fact that the code requires a lot of memory to compile.

The switch only informs the compiler about the memory costs it should plan for during compilation. In VS 2013, the default precompiled header buffer size is 75 MB, which is value that a complex project can reasonably exceed. In such situations, you can use /Zm to increase the limit. Alternately, you could invest significant work into reducing the complexity of your include files.

In most cases, it is a much better use of developers' time to increase /Zm.



Related Topics



Leave a reply



Submit