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

  • Home
  • SEARCH
  • 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 8716041
In Process

The Archive Base Latest Questions

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

Here is a simple C++ program which takes in a size arguments and allocates

  • 0

Here is a simple C++ program which takes in a size arguments and allocates an array of integers of that size. program is compiled using g++ under Linux running on a virtual machine with 32bit architecture.
When the application is called with argument (array size) above 1073741823* I get

Segmentation fault (core dumped)

error and with a value slightly smaller than that I get.

terminate called after throwing an instance of ‘std::bad_alloc’
what(): std::bad_alloc Aborted (core dumped)

here is the code:

/* dynamicAlloc.cpp */
#include <iostream> 
#include <stdlib.h> //for atoi
#include <cstdlib> // for rand() and srand()
#include <ctime> // for time()

using namespace std;
#define STR_LEN 256

int main(int argc, char* argv[])
{
    srand(time(0)); 

    unsigned int iArraySize = 1;
    if(argc < 2)
        return -1;

    iArraySize = atoi(argv[1]);

    int *pnValue = new int[iArraySize];
    if(pnValue == NULL)
    {
        cout << "cannot allocate array" << endl;
        return -2;
    }

    for(unsigned int iCounter = 0; iCounter < iArraySize; iCounter++)
    {
        pnValue[iCounter] = rand(); 
    }

    delete[] pnValue; 
    return 0;
}

Why am I getting two different errors?

also if I have a very big data that requires billions of data to be processed/massaged, do I have to use a database to handle such large amount of data or is there another method of handling large data sets?

thank you for reading

*1073741823 = (2 ^ 32(bit address)) / 4(int size in byte)) – 1

UPDATE

The output of ulimit -a is:

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 3808
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) 3808
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

The Ram size is configured to be 512MB. I thought since every program has it’s own virtual page (for a 32bit arch it’s 4GB I think) then I can use all of that virtual memory.

  • 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:59:05+00:00Added an answer on June 13, 2026 at 5:59 am

    You don’t have 4 gigabytes of memory available to you on a 32 bit machine. You have 4 gig total. What your program can access is less than that.

    You get a segfault with that huge value because you are creating an illegal address. The underlying machinery doesn’t even get a chance to try to allocate that memory. It goes kaboom before even attempting to make the allocation.

    With a slightly lesser value, the address is valid but something is preventing you from allocating that large a chunk of memory. You might not have that much memory, or you might have a limit that prevents you from taking that much memory. If it’s a soft limit you can raise it. If it’s a hard limit, you need sys admin privileges to raise it.

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

Sidebar

Related Questions

Here, i have a program, which takes arguments (how surprising...). I want him to
Here is a simple php program which gives a strange output. Can anyone explain
Here's a very simple program using the function: #include <windows.h> #include <tchar.h> #include <atlstr.h>
Well, i have written a simple python program that parses HTML with HTMLParser. Here
Im trying to write a simple program that takes 5 images and allows you
Here is the code of program, which should send a simple 'ping'. I know
I have a simple program which takes a video and plays it (though it
Hi i've got here a simple program, but it's not working properly. When i
Here is a simple program to output to a text file: #include <iostream> #include
Here is a very simple program: a = [[]]*3 print str(a) a[0].append(1) a[1].append(2) a[2].append(3)

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.