Hi all, i'm working on some exercises which i have to load data from Image library. I write a load function and it work fine except when the number of images in the library becomes large.

At this moment, the limited number if around 700 images. When the number reaches to a larger number, there will be error like this

Belove is my function:

``````void Image::load_Image_From_BMP()
{
FILE *ImageFile;

{
return;
}

dataR = (unsigned char**)malloc(sizeof(unsigned char*)* bmih.biHeight);
dataG = (unsigned char**)malloc(sizeof(unsigned char*)* bmih.biHeight);
dataB = (unsigned char**)malloc(sizeof(unsigned char*)* bmih.biHeight);
dataA = (unsigned char**)malloc(sizeof(unsigned char*)* bmih.biHeight);

for (int i = 0; i < bmih.biHeight; i++)
{
dataR[i] = (unsigned char*)malloc(sizeof(unsigned char) * bmih.biWidth);
dataG[i] = (unsigned char*)malloc(sizeof(unsigned char) * bmih.biWidth);
dataB[i] = (unsigned char*)malloc(sizeof(unsigned char) * bmih.biWidth);
dataA[i] = (unsigned char*)malloc(sizeof(unsigned char) * bmih.biWidth);

}

for (int row = 0; row < bmih.biHeight; row++)
{
for (int colum = 0; colum < bmih.biWidth; colum++)
{
theta[row][colum] = 0.0f;
r[row][colum] = 0.0f;
}
}

if (bmih.biBitCount  == 24)
{
for (int row = 0; row < bmih.biHeight; row++)
{
for (int columm = 0; columm < bmih.biWidth; columm++)
{
}
}
}

else if (bmih.biBitCount == 32)
{
for (int row = 0; row < bmih.biHeight; row++)
{
for (int columm = 0; columm < bmih.biWidth; columm++)
{

}
}
}

fclose(ImageFile);
}``````

and if i use the function like this, error will happen if the number_of_image becomes large (for example 800 images)

``````for (int i=0; i < number_of_image; i++)
{
}``````

## All 3 Replies

Why does that function not have a parameter?

Check the contents of fileLink list. Maybe the problem is bad data in the list. Change your program to just display all the nodes of that linked list (or whatever it is) instead of actually calling the load_Image... function. That will let you visually verify whether the list is ok or not.

@Ancient Dragon: Actually the code

``````for (int i=0; i < number_of_image; i++)
{
}``````

is just the example code. Even if the load_Image_From_BMP() runs on the same image for > 800 times, the same error still occurs.

The data list for each image is all right, i guarantee that because i print out to check for each image.

My problem is "When i use that load_image_from_BMP() function to load images from the library, if the library has large number of images (for example 800 images), then the error occurs like in the picture above"

I guess there is bug related to the memory, buffer or something like that.

You seem to be running out of memory; verify that malloc()s return a non-NULL pointer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.