We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I am working on MCB2300 (with LPC2378 processor). I have written a small function that will read the values into a matrix. But when the control comes to fread it completely hangs up, nothing can be done. Below is the my function which is giving problem
void loadImage(FILE* arq, unsigned char** Matrix){ int i,j; unsigned char tmp; long pos = 51; fseek(arq,0,0); for (i=0; i<300; i++){ for (j=0; j<400; j++){ pos+= 3; fseek(arq,pos,0); fread(&tmp,3,1,arq); Matrix[i][j] = tmp; } } }
Its working fine in GNU C. But when I have tried to use the same code in Keil uVision4, its is not working. Please let me know how to sort this problem
The type RGB is 3 bytes, but the compiler could add padding when working with arrays of RGB (sizeof(RGB) == 4). So this could increase memory usage to 4 bytes per one instance of RGB.
I have verified the sizeof(RGB) when memory is allocated by giving a printf statement. Always it is showing as 3 bytes only. So here no padding is done by compiler.
I have already tried previously by allocating one big chunk of memory for a three-dimensionsl array: unsigned char bitmap[height][width][3]. Even it did n't worked. In my application height and width are 320 and 240. But matrix with these values in not working. If height and width are very small values like 10,10 then it is working. But not for larger values
If height and width are very small values like 10,10 then it is working. But not for larger values
How much RAM do you have allocated for the heap? Do you have enough RAM for this? 320x240x3 = 225 Kbytes.
Again, that's meaningless!
You need to state precisely what did happen - and why you consider that to be "not working"!
What, exactly, failed?
How did it fail?
What debugging have you done to find the cause of the failure?
I have already tried previously by allocating one big chunk of memory for a three-dimensionsl array:
unsigned char bitmap[height][width][3]
So it's actually 320 x 240 x3 = 675K
I have defined a matrix like below
unsigned char bitmap[320][240]
After that I allocated the some elements into that matrix before reading pixel values to make sure whether all elements in the matrix are initialised in the following manner
for (i=0;i<320;i++){ for (j=0;i<240;j++){ bitmap[i][j]=j; } }
After this I am trying to print the values read in to the matrix using printf statement inthe following manner
for (i=0;i<320;i++){ for (j=0;i<240;j++){ printf(" %d ", bitmap[i][j]); } }
Once done I have compiled it. Compilation is done but I could n't run it. Nothing is printed
You keep ignoring my suggestions. What's the point in posting about your problems when you ignore the responses? How much RAM do you have? Do you have enough of it to hold your bitmap? If you define a variable at function scope (a so-called automatic variable), memory for it will be allocated on the stack. I am certain that your stack is not large enough to hold a variable that is 75 Kbytes in size. Hence, the program will not work.
My default heap size in startup file is Heap_Size EQU 0x00000800.
I have increased the heap size step by step and tested on images with different sizes. When I have set the heap size to 0x 00007000 , the final image that worked is of size 26.3 KB (109 x 82 x 3). But if I change heap value further it is not working. But my required image size is much larger. What things I need to do so that I can change heap value further and ensure it works with large images?
My IRAM1 settings are default (IRAM1: 0x40000000 Size: 0x8000)
OK, this is the 3rd time I'm asking this: how much RAM do you have? This is important for your application, as you should have realized by now. You indicated that you have 32 Kbytes of RAM. Obviously, this is too little.
In fact, you seem to ignore all responses from all posters!
"Compilation is done but I could n't run it"
There you go again - a meaningless statement!
Why couldn't you run it?
What, exactly, prevented you from running it?
What debugging have you done to find the problem?