I am using 64 bit Windows 7 Pro and Visual Studio 2010 Pro.
I am trying to allocate and use a buffer larger than 4 GB (to collect data at a high data rate).
Allocating and writing a buffer as a byte vector works fine. Allocating a buffer as an array of bytes works fine, but writing to this array quickly fails. (The last message printed is "buffer allocated.")
A note on vector partitioning does not fix the problem.
Below is my test program:
#include <iostream> #include <vector> #include <BaseTsd.h> using namespace std; int main() { const ULONG64 BUF_SIZE = 4 * 1024ULL * 1024ULL * 1024ULL; { vector<unsigned __int8> v(BUF_SIZE); cout << "vector allocated" << endl; for (ULONG64 i = 0; i < BUF_SIZE; ++i) { v[i] = 0xff; } cout << "vector written" << endl; } { unsigned __int8* buffer = new unsigned __int8[BUF_SIZE]; cout << "buffer allocated" << endl; for (ULONG64 i = 0; i < BUF_SIZE; ++i) { buffer[i] = 0xff; } cout << "buffer written" << endl; delete[] buffer; } return 0; }
UPDATE: I believe this is a compiler error. Take a look here: http://connect.microsoft.com/VisualStudio/feedback/details/553756/invalid-check-for-maximum-array-size-in-x64-compiler-c2148
source share