Help with Malloc 
Author Message
 Help with Malloc

Can anyone help?
Listed below is some code(Microsoft Visual C++)
It calc's the maximum allocation
that succeeds.  Why does it only return 255 Mb?
Can anyone tell me how to allocate 600Mb
(Need for large image processing) ?

#include <stdio.h>
#include <malloc.h>

// windows 95
// swap file min 512Mb max 1019Mb
// free space 1019Mb
// maximum allocation that succeeds is 255 Mb
// WHY WHY WHY
void main()
{
    unsigned int size;
    char *buff;
    size = 2048;
    buff = NULL;
    while (buff == NULL)
    {
        size -= 1;
        printf ("try allocation of %d Mb\n", size);
        buff = (char *) malloc(size * 1024 * 1024);
    }
    if (buff)
    {
        printf ("largest allocation is %d Mb\n", size);
        printf ("freeing allocation\n", size);
        free (buff);
    }
    else
    {
        printf ("no allocations succeded\n");
    }

Quote:
}



Mon, 31 Jul 2000 03:00:00 GMT  
 Help with Malloc

Hi Murrae,

You get a better result when you change your variable "size" to long
int.

Quote:

> Can anyone help?
> Listed below is some code(Microsoft Visual c++)
> It calc's the maximum allocation
> that succeeds.  Why does it only return 255 Mb?
> Can anyone tell me how to allocate 600Mb
> (Need for large image processing) ?

> #include <stdio.h>
> #include <malloc.h>

> // windows 95
> // swap file min 512Mb max 1019Mb
> // free space 1019Mb
> // maximum allocation that succeeds is 255 Mb
> // WHY WHY WHY
> void main()
> {
>     unsigned int size;
>     char *buff;
>     size = 2048;
>     buff = NULL;
>     while (buff == NULL)
>     {
>         size -= 1;
>         printf ("try allocation of %d Mb\n", size);
>         buff = (char *) malloc(size * 1024 * 1024);
>     }
>     if (buff)
>     {
>         printf ("largest allocation is %d Mb\n", size);
>         printf ("freeing allocation\n", size);
>         free (buff);
>     }
>     else
>     {
>         printf ("no allocations succeded\n");
>     }
> }

--
Rob Goudvis




Mon, 31 Jul 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Help with malloc() problem

2. Need some help with malloc ?!?

3. Help requested: malloc corrupting char **'s?

4. help with malloc

5. please help on malloc/free!

6. Help with malloc

7. help on malloc...

8. Help with malloc() and free()

9. Need Help with malloc-ing 2D arrays

10. help w/ malloc(), structures + functions

11. Need help with malloc

12. Need help monitoring malloc() and free()

 

 
Powered by phpBB® Forum Software