8 years, 3 months ago.

Any malloc size limitation on GR PEACH?

Hi, The program (listed below) only used 612.4kB of RAM out of 10MB, but during run time, the last malloc cannot be assigned.

Is there limitation in size for malloc even when there is indication of enough memory by the mbed compiler?

Thanks, Sung

Below are the additional information:

Below is the code (which can be compiled - Program Detial: Build shows that Flash used 39.9kB out of 8MB and RAM used 612.4kB out of 10MB ):

  1. include "mbed.h"

typedef struct { int width; int height; int maxgrey; unsigned char* data; int flag; } MyImage;

typedef struct { int width; int height; int* data; int flag; } MyIntImage;

int main() {

printf("\r\n");

MyImage imageObj; MyImage *image = &imageObj;

MyIntImage intImageObj; MyIntImage *intImage = &intImageObj;

MyIntImage intImage1Obj; MyIntImage *intImage1 = &intImage1Obj;

int size = 320*240;

image->data = (unsigned char*)malloc(sizeof(unsigned char)*(size)); printf("image->data addr = %d\r\n", image->data);

intImage->data = (int *)malloc(sizeof(int)*(size)); printf("intImage->data addr = %d\r\n", intImage->data);

intImage1->data = (int *)malloc(sizeof(int)*(size)); printf("intImage1->data addr = %d\r\n", intImage1->data);

free(image->data); free(intImage->data); free(intImage1->data);

}

Below is the output on the Hyperterminal: image->data addr = 537006552 intImage->data addr = 537083360 intImage1->data addr = 0

Be the first to answer this question.