I have something like this:
typedef int customType[10];
And I want a function like this
std::vector<customType*>& myFunc();
But there are some problems.
1) I need to allocate memory for every pointer to customType in the vector (do I?)
and doing
std::vector<customType*> A;
//some code to get length
for (i = 0; i < length; i++)
{
A[i] = new customType;
}
is wrong because of an error:
IntelliSense: a value of type "int *" cannot be assigned to an entity of type "customType*"
2) In common, is it a good way to store such data? Maybe I should make an array of 1 dimension with everything stored in one line and use something like
A[i*innerLength+j]
to access elements?
I would generally recommend using something like the below and doing the array indexing yourself.
At really large sizes it may be better to break it up. It’s just a lot of contiguous memory to allocate in a block. “Really large” is pretty subjective, and you probably can get away with a lot larger sizes than most people would expect. Let the profiler tell you when it’s a problem.
If you have access to C++11, then this would be another option.