Malloc issue

Hard Maker
Sat Feb 18 17:55:00 GMT 2012

Hi list,
I'm working with newlib in a cortex-m3 microcontroller (developing and 
study how work), debugging a little aplicatino I found the malloc 
assigments no depend of the type of data used. I'm not shure how explain 
this in english, but with this code is more simple:

#include <stdio.h>
#include "kit.h"
#include "lcd_drv.h"
#include <malloc.h>

int main(int argc, char *argv[]){
     char *m1;
     short *m2;
     int *m3;
     float *m4;
     long double *m5;
     m1 = (char *)malloc(sizeof(char)); // 1 Byte
     m2 = (short *)malloc(sizeof(short)); // 2 Byte
     m3 = (int *)malloc(sizeof(int)); //  4 Bytes
     m4 = (float *)malloc(sizeof(float));  // 4 Bytes
     m5 = (long double *)malloc(sizeof(long double)); // 8 bytes
     return 0;
All address assigned to m1, m2, m3, m4 and m5 pointers have 16 bytes of 
distance. The values show in debugger after last malloc are:
m1 = 0x20005d90
m2 = 0x20005da0
m3 = 0x20005db0
m4 = 0x20005dc0
m5 = 0x20005dd0
My question is: Why all pointers have 16 bytes of distance if they point 
to diferentes types of data? Searching about malloc aligment I found the 
default value is 8, there are some relationship?

I'm using newlib version 1.19.0

thank's a lot.


More information about the Newlib mailing list