Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,781 questions

10,865 answers

573 users

How to allocate big memory size until you meet your system limit in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
        
int main()
{
    char *p = NULL;

    for (long long int i = 1; i < 100000000L; i += 100000)
    {
        long long int size = 10000 * i;
        p = (char*)malloc(size);
        if (p != NULL)
        {
            printf("Allocate: %llu bytes\n", size);
            free(p);
        }
        else
        {
            printf("Cannot allocate size: %llu bytes\n", size);
            break;
        }
    }
    return 0;
}


/*
run:

Allocate: 10000 bytes
Allocate: 1000010000 bytes
Allocate: 2000010000 bytes
Allocate: 3000010000 bytes
Allocate: 4000010000 bytes
Allocate: 5000010000 bytes
Allocate: 6000010000 bytes
Allocate: 7000010000 bytes
Allocate: 8000010000 bytes
Allocate: 9000010000 bytes
Allocate: 10000010000 bytes
Allocate: 11000010000 bytes
Allocate: 12000010000 bytes
Allocate: 13000010000 bytes
Allocate: 14000010000 bytes
Allocate: 15000010000 bytes
Allocate: 16000010000 bytes
Allocate: 17000010000 bytes
Allocate: 18000010000 bytes
Allocate: 19000010000 bytes
Allocate: 20000010000 bytes
Allocate: 21000010000 bytes
Allocate: 22000010000 bytes
Allocate: 23000010000 bytes
Cannot allocate size: 24000010000 bytes

*/

 




answered Mar 29 by avibootz
edited Mar 29 by avibootz
...