This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: mallocr.c implementation


Hi Craig,

    int size = 1024*1024;
    char *c = malloc(62 * size);

This allocates 62MB of memory just fine (the XBOX has 64MB physical RAM). If I use 63, then it hangs (which I am investigating separately). So, I know that I can successfully allocate up to at least 62MB.

Just being paranoid - but have you checked that the 62MB is actually there ? Ie can you use all of it ? If there a problems in the memory allocation system somewhere then it may be that the apparent success of your 62Mb malloc call is in fact a fake.


Now, if I change the program to look like:
int size = 1024*1024;
for (int i = 0; i < 62; i++)
char *c = malloc(size);


I would have suspected that this should work too, but it only manages to allocate eight buffers. Why such a disparity? I might have understood if it could only get to 61 or 60, but only 8?

Maybe only 8 separate calls to malloc() can be supported ? If you
change 'size' to say 1024, can you get more allocated buffers ? Incidentally what happens when you try to allocate the ninth megabyte buffer ? Does malloc return NULL ?


If you free the 8 buffers can you allocate 8 more ? Or 9 more ?

Usually a problem like this will be in your kernel's memory allocation system somewhere, rather than in the newlib code. So if you are able to enable debugging there then I suspect that that would help.

Cheers
  Nick


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]