0

I'm currently trying to generate a 100x100x100 matrix of integers in C++. However, I was running into some stack overflow issues with the general C++ arrays.

My project is already using the Eigen library for Linear Algebra so if possible I'd like to use that but I've been having trouble trying to find reliable implementations for a 3D matrix. I'm strictly going to be using this for coefficient wise math so I don't need to worry about any algebra capabilities. I just need to be able to increment those values.

Any advice? Here is a basic code for how I was getting the stack over flow

#include<iostream>
#include<fstream>
#include<cmath>
#include<vector>

int main()
{
int V1[100][100][100];

return 0;
}

  • *However, I was running into some stack overflow issues with the general C++ vector libraries.* -- When you say "vector libraries*, are you referring to `std::vector`? Since a `std::vector` gets its memory store from the heap, there shouldn't have been any stack overflow issues. – PaulMcKenzie Apr 14 '20 at 19:58
  • I did just a flat >> Definition and was still running into some issues. –  Apr 14 '20 at 19:59
  • The issue clearly isn't going to be a stack overflow issue using that definition. A heap exhaustion issue maybe, but even that is remote, since a modern day desktop OS should have much more than `1000000 * sizeof(int)` available free memory. – PaulMcKenzie Apr 14 '20 at 20:01
  • I apologize I edited my question. I was getting the stack overflow with the code given. Not with the vector library. I was unable to get that working. –  Apr 14 '20 at 20:03
  • Well the stack overflow is to be expected, since stack memory is limited. You probably have 2 MB of stack available (some systems default to 8 MB). – PaulMcKenzie Apr 14 '20 at 20:04
  • How could I perform a simple implementation with the vector library? –  Apr 14 '20 at 20:05
  • If you need to send a 3D array, but in contiguous memory (I don't know Eigen well enough), then the triple vector isn't going to help. You could try [this](https://stackoverflow.com/questions/52068410/allocating-a-large-memory-block-in-c/52069368#52069368), which allocates the entire 3D data in one contiguous chunk of memory. – PaulMcKenzie Apr 14 '20 at 20:07

0 Answers0