Linked Questions
46 questions linked to/from 1D or 2D array, what's faster?
1 vote
1 answer
636 views
Why 2D arrays run significantly slower than 1D arrays in java [duplicate]
For one of my program I need large memory, I have done this with two different implementations, these are as follows: int SIZE = 1000000000; int[] rnums = new int[SIZE]; byte[] d1 = new byte[2 *...
0 votes
2 answers
250 views
2d array and 1d array storage comparison? [duplicate]
I have an issue understanding some things about arrays in C++. If I have array with 3 rows and 4 colomns and I create them as 1d array and accessing each row data by looping through the array by 4 ...
1 vote
0 answers
228 views
Accessing a matrix using single pointer Vs double pointer [duplicate]
To access a matrix we can use a double pointer, and then use 2d arrays with index i, j. for rows a column. For example the element (1,2) could be addressed as A[1][2]. Another method is to use ...
-3 votes
1 answer
97 views
using 2-dimensional arrays is faster than two of 1-dimensional arrays? [duplicate]
static int ud[] = new int[] { 0, 0, 1 }; static int lr[] = new int[] { -1, 1, 0 }; static int dirs[][] = { { 0, 1 }, { 1, 0 }, { 0, -1 } }; public static int solve(int r, int c, int dir) { if (...
0 votes
0 answers
82 views
In C++ is it looping through a 1D array faster than a 2D array? [duplicate]
If we had two arrays, bool trueFalse[10][10]; bool falseTrue[100]; and we looped through them like this: for(int i = 0; i < 10; i++) { for(int k = 0; k < 10; k++) { trueFalse[i]...
2560 votes
8 answers
402k views
What is The Rule of Three?
What does copying an object mean? What are the copy constructor and the copy assignment operator? When do I need to declare them myself? How can I prevent my objects from being copied?
526 votes
10 answers
211k views
What is meant by Resource Acquisition is Initialization (RAII)?
What is meant by Resource Acquisition is Initialization (RAII)?
20 votes
7 answers
16k views
c++ Vector, what happens whenever it expands/reallocate on stack?
I'm new to C++ and I'm using the vector class on my project. I found it quite useful because I can have an array that automatically reallocates whenever it is necessary (ie, if I want to push_back an ...
11 votes
6 answers
45k views
What is the most efficient way to initialize a 3D vector?
I have a 3D string vector in C++: vector<vector<vector<string>>> some_vector That I am trying is to find a fast method to allocate memory for it. I tried to define it with two ...
8 votes
3 answers
7k views
What are the Issues with a vector-of-vectors?
I've read that a vector-of-vectors is bad given a fixed 2nd dimension, but I cannot find a clear explanation of the problems on http://www.stackoverflow.com. Could someone give an explanation of why ...
9 votes
3 answers
1k views
Why does C++ multiplication with dynamic array work better than std::vector version
I am implementing the C++ multiplication for matrices with different data structures and techniques (vectors , arrays and OpenMP) and I found a strange situation... My dynamic array version is working ...
4 votes
3 answers
12k views
Problems using 3-dimensional vector
How can I work with a 3 dimensional vector in C++? vector<vector<vector<int> > > vec (1,vector<vector<int> >(1,vector <int>(1,12))); When I try something like this ...
1 vote
4 answers
8k views
How to represent 2D matrix in c++
Is it faster to represent at 2D matrix as an array of arrays, or as a 1D array with a function that converts co-ordinates to the corrisponding array index?
0 votes
7 answers
6k views
How to declare a pointer to a 2d float matrix?
Im trying to declare a pointer to a 2d float matrix in order to have a dynamical behaviour of my image data but Im having a compilation error C2057: expected constant expression. I thought a pointer ...
1 vote
1 answer
17k views
Creating and filling a matrix by input in C++
I'm trying to write a program in C++ which is able to multiply matrices. Unfortunately, I'm not able to create a matrice out of 2 vectors. The goal: I type in the number of rows and the number of ...