You’ve exceeded your stack space given by the OS. If you need more memory, the easiest way is to allocate it dynamically:
int N=1000000; short* res = new short[N];
However, std::vector
is preferred in this context, because the above requires you to free
the memory by hand.
int N = 1000000; std::vector<short> res (N);
If you can use C++11, you can possibly save some fraction of time by using unique_ptr
array specialization, too:
std::unique_ptr<short[]> res (new short[N]);
Both of the automatic methods above can still be used with familiar res[index]
syntax thanks to overloaded operator[]
, but to get the raw pointer for memory operations you’d need res.data()
with vector
or res.get()
with unique_ptr
.
Related Posts:
- What is a segmentation fault?
- Why do we need virtual functions in C++?
- How do I fix a “Expected Primary-expression before ‘)’ token” error?
- What are the rules of the std::cin object in C++?
- C++ code file extension? What is the difference between .cc and .cpp
- C++ Error: ISO C++ Forbids Comparison Between Pointer and Integer [-fpermissive]
- How to append text to a text file in C++?
- Segmentation Fault (core dumped) C++
- Segmentation fault error 11 C++
- In C++, what is wx.h?
- Using “super” in C++
- new types may not be defined in a return type – C++
- Program received signal SIGSEGV, Segmentation fault
- declaring a priority_queue in c++ with a custom comparator
- Program received signal SIGSEGV, Segmentation fault
- C++ undefined reference to WinMain@16 (Code::Blocks)
- bit vectors in c++
- Very basic inheritance: error: expected class-name before ‘{’ token
- mkdir c++ function
- Fixing Segmentation faults in C++
- Error: “expected primary-expression before int”
- Operator Overloading C++; too many parameters for << operation
- How do I check if a Key is pressed on C++
- How can I convert MP3 file to a Base64 encoded string? [closed]
- What is a sanity test/check
- What is an instance variable in Java?
- Discord music bot not working
- Why in C++ do we use DWORD rather than unsigned int? [duplicate]
- Split a string using C++11
- What is a bitmask and a mask?
- error: expected unqualified-id error: Meaning and fix? [duplicate]
- How to track down a “double free or corruption” error
- The Definitive C++ Book Guide and List
- undefined reference to `WinMain@16′
- What is C# equivalent of
- Why does the C++ STL not provide any “tree” containers?
- Echo newline in Bash prints literal \n
- Compiling C++11 with g++
- Setting an int to Infinity in C++
- dynamic_cast and static_cast in C++
- What exactly is std::atomic?
- Separating class code into a header and cpp file
- Raise to power in R
- How to ensure that a std::map is ordered?
- How to write C++ getters and setters
- std::out_of_range error?
- Center text in fixed-width field with stream manipulators in C++
- ctypes error: libdc1394 error: Failed to initialize libdc1394
- Reason for the exception java.lang.VerifyError: Bad type on operand stack
- Understanding glm::lookAt()
- How to get current timestamp in milliseconds since 1970 just the way Java gets
- What is the best open XML parser for C++?
- Compiling simple Hello World program on OS X via command line
- Cannot open output file, permission denied
- Strange error C2131: expression did not evaluate to a constant in VC 2015
- pandoc document conversion failed with error 43 : pdflatex: The memory dump file could not be found
- ERROR: transport error 202: bind failed when starting Tomcat 7 in debug mode
- When to use const char * and when to use const char []
- Arithmetic Overflow in mips
- What is wrong with using goto?
- How to change angular port from 4200 to any other
- Double pointer array in c++
- Render HTML string as real HTML in a React component
- How to draw lines in Java
- C++ compiler error: “return type specification for constructor invalid”
- What is “pass-by-name” and how does it work exactly?
- error: ISO C++ forbids in-class initialization of non-const static member
- Function call missing argument list to create pointer
- cannot specify explicit initializer for arrays
- What does ** mean in C++?
- is it possible to get the MAC address for machine using nmap
- Incomplete type is not allowed: stringstream
- Import error No module named skimage
- Converting bool to text in C++
- mport win32ui in python 3.6
- clearing a vector of pointers [duplicate]
- Evaluate a string with a switch in C++ [duplicate]
- Call to undefined function `get_plugin_data()`
- Contact Form 7 – Execute code AFTER mail send [closed]
- Rendering javascript in render_callback php Code
- 100% uptime for a web application
- How to assign permissions to ApplicationPoolIdentity account
- Is it bad to redirect http to https?
- Using DD for disk cloning
- What tool do you use to monitor your servers?
- Sudo as different user and running screen
- What is the difference between Load Balancer and Reverse Proxy?
- Should servers be turned off at night?
- Where to check log of sendmail?
- How can I see Time-To-Live (TTL) for a DNS record?
- Rsync difference between –checksum and –ignore-times options
- Should I use tap or tun for openvpn?
- Smell of rotten eggs in the server room
- Should we host our own nameservers?
- Ansible: Execute task only when a tag is specified
- Is a CNAME to CNAME chain allowed?
- How does a team of Systems Administrators share passwords securely?
- Apache2 config variable is not defined
- How dangerous is a wet server room floor
- Why is rsync skipping the main directory?