Hey I need to do a binary search on an array of 2 million elements but my programs bugging out at a char array of 1,100,000. A char array of 1,000,000 is the most my PC is handling. 2,000,000 chars should be 16,000,000 bits. My ram is 8 GB which should be 68,719,476,736(68 billion) bits which I think should be able to hold the 2 million chars. Does anyone know whats going on?
This code bugs out...
using namespace std;
With the caveat that we are getting into implementation specific details here.
The C++ standard does not mention either stack storage or heap storage; instead it uses the abstract concept of 'storage durations' - static storage duration, automatic storage duration, dynamic storage duration and in C++11, thread storage duration. In simple terms, the standard is only concerned about the lifetime of objects (and the duration for which the memory for an object would be available). The standard library provides a default implementation of the allocator for objects with a dynamic storage duration. It too does not talk of a heap - conceptually, this memory comes from the 'free store'.
An implementation can store all objects in a program on a run-time stack, or on several different stacks, or on one heap, or many arenas (which may contain individual heaps of their own), or in a memory mapped disk file, or anywhere else that it pleases for that matter - as long as it ensures that the lifetime of objects conform to the storage durations as specified by the IS.