bad-alloc

Reading large (~1GB) data file with C++ sometimes throws bad_alloc, even if I have more than 10GB of RAM available

一个人想着一个人 提交于 2019-12-06 15:46:00
I'm trying to read the data contained in a .dat file with size ~1.1GB. Because I'm doing this on a 16GB RAM machine, I though it would have not be a problem to read the whole file into memory at once, to only after process it. To do this, I employed the slurp function found in this SO answer . The problem is that the code sometimes, but not always, throws a bad_alloc exception. Looking at the task manager I see that there are always at least 10GB of free memory available, so I don't see how memory would be an issue. Here is the code that reproduces this error #include <iostream> #include

cuda/thrust: Trying to sort_by_key 2.8GB of data in 6GB of GPU RAM throws bad_alloc

纵然是瞬间 提交于 2019-12-05 18:53:18
I have just started using thrust and one of the biggest issues I have so far is that there seems to be no documentation as to how much memory operations require. So I am not sure why the code below is throwing bad_alloc when trying to sort (before the sorting I still have >50% of GPU memory available, and I have 70GB of RAM available on the CPU)--can anyone shed some light on this? #include <thrust/device_vector.h> #include <thrust/sort.h> #include <thrust/random.h> void initialize_data(thrust::device_vector<uint64_t>& data) { thrust::fill(data.begin(), data.end(), 10); } int main(void) { size

Strange std::bad_alloc

不打扰是莪最后的温柔 提交于 2019-12-05 02:51:16
As far as I know, there are three reasons why a std::bad_alloc can be thrown: The process requests more memory than what can be served The address space is too fragmented to serve a request for a large chunk of contiguous memory The heap management datastructure is corrupted We have code which runs into a std::bad_alloc, but none of the above reasons seem to apply. The datastructure is a graph stored as a std::list of vertices, where each vertex stores again a std::list of the edges of which it is part of as well as some amount of contiguous data. For small graphs (<= 100'000 vertices), the

Why new[-1] generates segfault, while new[-2] throws bad_alloc?

若如初见. 提交于 2019-12-04 17:31:29
问题 I tried to test bad_alloc exception by passing some negative arguments to new[] . When passing small negative numbers I get what I hoped for - a bad_alloc . However, when passing -1 , I can see that my object is constructed thousands of times (I print static counter in constructor) and the application terminates with segfault. new[] converts signed integer to size_t , so -1 is the max of size_t and -2 is the maximum - 1 and so on. So why new[] throws exception when receiving some huge number,

what(): std::bad_alloc - am I out of memory?

江枫思渺然 提交于 2019-12-02 07:20:24
My dataset: 500,000 points in 960 dimensions. The size of the file is 1.9 GB (1,922,000,000 bytes). The code works for smaller data sets, but for this it will crash in the same point every time. Here is a minimal example: #include <iostream> #include <vector> template<typename T> class Division_Euclidean_space { public: /** * The data type. */ typedef T FT; /** * Constructor, which * sets 'N' and 'D' to zero. */ Division_Euclidean_space() : N(0), D(0) { } /** * @param n - size of data */ void setSize(size_t& n) { N = n; } /** * @param n - size of data */ void setSize(int n) { N = n; } /** *

Why am I getting “Invalid Allocation Size: 4294967295 Bytes” instead of an std::bad_alloc exception?

房东的猫 提交于 2019-12-01 04:18:58
问题 I wrote the following piece of code to allocate memory for an array: try { int n = 0; cin >> n; double *temp = new double[n]; ... } catch(exception& e) { cout << "Standard exception: " << e.what() << endl; exit(1); } Of course I'm checking n for negative values etc. but when I enter some large Number over 536*(10^6) I'm not getting a bad-alloc exception but a "Invalid Allocation Size: 4294967295 Bytes" Crash. E.G. I enter n = 536*(10^6) --> bad-alloc exception I enter n = 537*(10^6) -->

Why does my program occasionally segfault when out of memory rather than throwing std::bad_alloc?

风流意气都作罢 提交于 2019-12-01 03:09:41
I have a program that implements several heuristic search algorithms and several domains, designed to experimentally evaluate the various algorithms. The program is written in C++, built using the GNU toolchain, and run on a 64-bit Ubuntu system. When I run my experiments, I use bash's ulimit command to limit the amount of virtual memory the process can use, so that my test system does not start swapping. Certain algorithm/test instance combinations hit the memory limit I have defined. Most of the time, the program throws an std::bad_alloc exception, which is printed by the default handler, at

Why does my program occasionally segfault when out of memory rather than throwing std::bad_alloc?

南笙酒味 提交于 2019-12-01 00:05:14
问题 I have a program that implements several heuristic search algorithms and several domains, designed to experimentally evaluate the various algorithms. The program is written in C++, built using the GNU toolchain, and run on a 64-bit Ubuntu system. When I run my experiments, I use bash's ulimit command to limit the amount of virtual memory the process can use, so that my test system does not start swapping. Certain algorithm/test instance combinations hit the memory limit I have defined. Most

“std::bad_alloc”: am I using too much memory?

穿精又带淫゛_ 提交于 2019-11-29 09:21:27
The message: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc I looked at the gdb backtrace and this is the lowest level method in there that I implemented myself: /* * get an array of vec3s, which will be used for rendering the image */ vec3 *MarchingCubes::getVertexNormalArray(){ // Used the same array size technique as getVertexArray: we want indices to match up vec3 *array = new vec3[this->meshPoints.getNumFaces() * 3]; //3 vertices per face int j=0; for (unsigned int i=0; i < (this->meshPoints.getNumFaces() * 3); i++) { realVec normal = this-

“std::bad_alloc”: am I using too much memory?

℡╲_俬逩灬. 提交于 2019-11-28 03:02:55
问题 The message: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc I looked at the gdb backtrace and this is the lowest level method in there that I implemented myself: /* * get an array of vec3s, which will be used for rendering the image */ vec3 *MarchingCubes::getVertexNormalArray(){ // Used the same array size technique as getVertexArray: we want indices to match up vec3 *array = new vec3[this->meshPoints.getNumFaces() * 3]; //3 vertices per face int j=0;