I have a program that dynamically allocates an array and uses it. The thing is that under certain situations this array will get infinitely long. As such I would like to know if/when the array has gotten too long and then start saving it to a file (where length will not be an issue) Here is an example:
unsigned char *myArray=new unsigned char[len];
//if len>max allowed memory:
FILE *myFile=fopen("myFile.dataFile","wb+");
for (int i=0; i<len; ++i)
{
fprintf("%c",myOtherData[i],myFile);
}
//else
for (int i=0; i<len; ++i)
{
myArray[i]=myOtherData[i];
}
I was thinking that maybe new[] returns NULL if there is not enough space or something?