Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a problem in memory allocation

Status
Not open for further replies.

jayjay60

Programmer
Jun 19, 2001
97
FR
Hi everybody,

I have a strange problem with an allocation of memory for pointers of pointers.

i have done this function to allocate memory for 2 pointers of pointers:

void LoadHistoDB::AllocComptStartEndMin(long RowSize,long ColSize)
{
long i;

pComptStartMineure=new double* [RowSize];
pComptEndMineure=new double* [RowSize];

for(i=0;i<RowSize;i++)
{
pComptStartMineure=new double[ColSize];
pComptEndMineure=new double[ColSize];
}
}

So, after the allocation is done, i want to put value in them, ik that:

pComptStartMineure[j]=i
pComptEndMineure[k]=i

i don't want to post all my code because it will be too long.

So when i test my application with debug method (calling the application with F5!)

When i>120 i could see in the debug window this message in front of pComptStartMineure:

CXX0030:expression cannot be evaluated

and i could see this same message for pComptEndMineure when i>202.

So where is the problem?

Thanks in advance for your help

jayjay
 
i think
pComptStartMineure=new double[ColSize];
pComptEndMineure=new double[ColSize];

should be
pComptStartMineure=new double[ColSize];
pComptEndMineure=new double[ColSize];
 
void LoadHistoDB::AllocComptStartEndMin(long RowSize,long ColSize)
{
if(RowSize <= 0 || ColSize <= 0) {
//Can't allocate
return;
}
long i;

pComptStartMineure=new double* [RowSize];
pComptEndMineure=new double* [RowSize];
if(pComptStartMineure == NULL || pComptEndMineure == NULL) {
//not enough memory
return;
}
for(i=0;i<RowSize;i++)
{
pComptStartMineure [ i ] =new double[ColSize];
pComptEndMineure [ i ] =new double[ColSize];
}
}
Do You have that too?
void LoadHistoDB::FreeComptStartEndMin(long RowSize)
{
long i;

if(pComptStartMineure == NULL || pComptEndMineure == NULL) {
//nothing allocated
return;
}
for(i=0;i<RowSize;i++)
{
if(pComptStartMineure [ i ])
delete [] pComptStartMineure [ i ];
if( pComptEndMineure [ i ] )
delete [] pComptEndMineure [ i ];
}
if(pComptStartMineure)
delete [] pComptStartMineure;
if(pComptEndMineure)
delete [] pComptEndMineure;
}
 
I will try what you suggest to me, but beore doing it, i would like to know how i could solve the problem which break the program if there is not enough memory, because i think it was what happen?

in your post it's this condition:
&quot;
if(pComptStartMineure == NULL || pComptEndMineure == NULL)
{
//not enough memory
return;
}

how could we solve that, because if my application need of X rows and the allocation couldn't be done, it will be very embarrassing!

thanks for your answer

jayjay
 
Free memory (exit some applications). If You have again not enough memory, add more memory to Your PC - there are no another easy way.
You can swap a part of Your info on disk, but it is not easy, it will works very slowly and I never seen any sample for that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top