Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8713597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:22:47+00:00 2026-06-13T05:22:47+00:00

Possible Duplicate: Can you allocate a very large single chunk of memory ( >

  • 0

Possible Duplicate:
Can you allocate a very large single chunk of memory ( > 4GB ) in c or c++?

I am running the following program on my computer:

#include <stdio.h>
#include <stdlib.h>

#define ONE_GIGABYTE 1024*1024*1024


int main(void) {
    int ctr=0;

    for (;;) {
        char *ptr = (char*)malloc(ONE_GIGABYTE*sizeof(char));
        if (ptr == 0)
            return -1;

        ctr++;
        printf("%d\n", ctr);
    }
}

flyrev@stargazer:~/weirdstuff$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 128957
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 128957
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
flyrev@stargazer:~/weirdstuff$ free -g
             total       used       free     shared    buffers     cached
Mem:            15          6          8          0          0          4
-/+ buffers/cache:          2         13
Swap:            9          0          9
flyrev@stargazer:~/weirdstuff$ clang malloc-program.c 
flyrev@stargazer:~/weirdstuff$ ./a.out 
1
2
flyrev@stargazer:~/weirdstuff$ 

What is going on here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:22:49+00:00Added an answer on June 13, 2026 at 5:22 am

    You’re not running out of memory, you’re running on a 32 bit system and so are running out of address space, you might reasonably expect to be able to allocate 4Gb on a 32 system since:

    2^32 = 4Gb

    However, on most operating systems, at least 50% of the available address space is actually reserved for use by the kernel so you can only have half of it.

    On Linux, it is possible to use significantly more than 4Gb in 32 bit mode by switching to use a PAE kernel. Many Linux distributions provide a PAE kernel as a package if you need one.

    EDIT: As Dietrich notes: PAE allows more memory to be used, but still only gives you 4 GiB of address space. So with 16 GiB you can have 8 programs with 2 GiB each, but you still can’t have one program with more than 2-ish GiB

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can a local variable’s memory be accessed outside its scope? #include <iostream>
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Can I run from command line program created by Eclipse? I am
Possible Duplicate: Can I set a breakpoint on 'memory access' in GDB? I want
Possible Duplicate: Can't convert String into integer in ruby/ruby-on-rails I'm running through a tutorial
Possible Duplicate: Can the template parameters of a constructor be explicitly specified? following up
Possible Duplicate: Allowed memory size of X bytes exhausted I'm hitting a very tricky
Possible Duplicate: Can I tell Linux not to swap out a particular processes' memory?
Possible Duplicate: Can't find socket.io.js Well when using socket.io you need to include the
Possible Duplicate: Can I scroll a ScrollView programmatically in Android? I have a chat

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.