Group: comp.lang.c++
From: mr.xiaofan.li@gmail.com
Date: Sunday, February 10, 2008 12:07 PM
Subject: Re: Vitual memory problem

On Feb 10, 4:20 pm, Klaib wrote:
> Hi
> 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.
> Note: i can't reduce the arrays
> Thanks a lot for helping
>
> Errors type:
> * std:: bad-alloc
> * Assertion faild: !" Bad error code", file c:\\helena\\bcc\\util-
> common\\vMem.c, line 714
>
> This is the part of my code that i used:
>
> char*** create3Darray(int m, int n, int l)
> {
> char*** array;
> int i;
>
> array = new char**[m];
> for (i = 0; i < m; i++)
> array[i] = create2Darray(n, l);
> return array;
> }
>
> //-----------------------------------------------------------
> //-------------------------------------------------------------
>
> char** create2Darray(int n, int l)
> {
> char** array;
> int j;
>
> array = new char*[n];
> for (j = 0; j < n; j++)
> array[j] = new char[l];
>
> return array;
> }
>
> //--------------------------------------------------------
> //--------------------------------------------------
>
> char* create1Darray(int n)
> {
> char* array;
> array = new char[n];
>
> return array;
> }
> //---------------------------------------------------------
> //----------------------------------------------------
>
> void delete2Darray(char** array, int m)
> {
> int j;
>
> for(j = 0; j < m; j++)delete [] array[j];
> delete [] array;
> array=NULL;
>
> }
>
> //---------------------------------------------------------
> //----------------------------------------------------
> void delete1Darray(char* array)
> {
> delete [] array;
> array=NULL;}
>
> //-------------------------------------------------
>
> //---------------------------------------------
> void delete3Darray(char*** array, int m, int n)
> {
> int i, j;
> for(i = 0; i < m; i++)
> {
> for(j = 0; j < n; j++)delete [] array[i][j];
> delete [] array[i];
> }
>
> delete [] array;
>
> }

You can easily allocate the whole bunch of memory at once by creating
a char array of size m*n*... (whatever the dimension is). Wrap it up
to a class and provide access methods such as my_array(i,j).

Safety Articles | Usenet Groups | Usenet News | Bluegrass