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 7557555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:09:42+00:00 2026-05-30T12:09:42+00:00

I need to set an array from 1 to 2 million for my current

  • 0

I need to set an array from 1 to 2 million for my current project. The problem is that I get a memory error when I try to execute…

Edit:

This is for a ProjectEuler problem which I have already solved. However, I am refactoring the code to do it much faster (original time was ~90 secs).

I’m using the sieve of eratosthenes to mark the primes from 0 to 2mil. Wikipedia article on this

EndEdit

<?php
range(0,2000000);
?>

obviously if this won’t work, the rest of the code won’t work.

Any ideas?

P.S. I tried ini_set('memory', '30M'); , but that didn’t work either.

Edit

Thanks to all who pointed out that the memory would need to be much larger than I first anticipated. I solved the problem by throwing in ini_set('memory_limit', '4000000000'); //about 3.73 gig

EndFinalEdit

  • 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-05-30T12:09:44+00:00Added an answer on May 30, 2026 at 12:09 pm

    If you can set at arbitrary place and get data from arbitrary index there is no point of sequential array.

    // completely acceptable in php
    $data[2000000] = 2000000; 
    

    If you are solving this euler problem in console (what I usually do), then run the php file with -d memory_limit=4G parameter. It’ll run with 4 GB of memory.

    php -d memory_limit=4G /path/to/euler/problem.php 
    

    BTW You can create some magic class which can mimic that you have a big array like that. 🙂

    class MySuperCoolLongIntArray{
        private $data=array();
        public get_int($index){
            return isset($this->data[$index])? $this->data[$index]: 0;
        }
        public set_int($index, $value){
            $this->data[$index]=$value;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to set the size of array. After that I start to input
I need to loop through a set of 2-dimensional array of hidden input fields
I need to be able to set the size of an array based on
I need to produce an array that is formatted as follows: Array( Array([100000116287110]=> Array([name]
I have a Activity that pulls an Array from the previous Activity . I
I need to drop into C++ from C# and bring back a 2D array
first,i need to count the items from array. <dict> <key>New item</key> <array> <string>apple</string> <string>orange</string>
Need set zoom for camera preview...
I need Set collection, where its items will be identified by items class. Something
I need to set the height of every textbox on my form, some of

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.