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

Bonsai Boy of New York Bonsai Trees and Accessories

Website Domains Names & Hosting | Domain.com

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

DreamHost Web Hosting


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Liquid Web Cloud VPS Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

12,336 questions

16,793 answers

573 users

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

Online Web Development & Programming Courses | Udemy
31 views
asked Mar 29, 2018 by avibootz
edited Mar 29, 2018 by avibootz

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, 2018 by avibootz
edited Mar 29, 2018 by avibootz
...