Re: Vitual memory problem
Klaib <mom.klaib@gmail.com> wrote:
I am a student doing my project, my program needs a big arrays size.
i used the following functions to create and delete the pointers, but
i have problems based on virtual memory during the the run time "
after 2 or 3 hour", Please help me to increase cBuilder virtual
memory or solving this problem.
If your program crashes due to starved memory after 2 or 3 hours, then
you probably are not deleting your arrays.
You can avoid this problem by wrapping your arrays in classes and using
RAII to make sure the memory is deleted when you are done with it.
A simple class to start with:
class array3D {
int m, n, i;
std::deque<char> data;
public:
array3D( int m, int n, int i ):
m( m ),
n( n ),
i( i ),
data( m * n * i )
{ }
char at( int x, int y, int z ) const {
// can someone double check my math in the below?
return data[x * n * i + y * i + z];
}
char& at( int m, int n, int i ) {
return data[x * n * i + y * i + z];
}
};
I use a deque in the above instead of a vector, because the OP is
implying that his data is very large and a deque is less likely to fail
when the memory is fragmented.