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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:27:46+00:00 2026-05-21T03:27:46+00:00

This is in relation to my post here but taken in a completely different

  • 0

This is in relation to my post here but taken in a completely different direction
Charset detection in PHP

essentially, i’m looking to reduce the memory that many huge arrays cause.

These arrays are just full of integers but seeing as PHP uses 32bit and 64 bit integers internally (depending which version you have compiled for your CPU type), it eats the memory.

is there a way to cheat PHP into using 8bit or 16bit integers?

I’ve thought about using pack(); to accomplish this so I can have an array of packed binary values and just unpack them as I need them (yes I know this would make it slower but is much faster than the alternative of loading and then running through each array individually as you can stream the text through so they all need to be in memory at the same time to keep speed up)

can you suggest any better alternatives to accomplish this? i know it’s very hacky but I need to prevent huge memory surges.

  • 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-21T03:27:47+00:00Added an answer on May 21, 2026 at 3:27 am

    Don’t tell nobody!

    class IntegerstringArray IMPLEMENTS ArrayAccess {
    
        var $evil = "0000111122220000ffff";
    
                     // 16 bit each
    
    
        function offsetExists ( $offset ) {
            return (strlen($this->evil) / 4) - 1 >= $offset;
        }
    
        function offsetGet ( $offset ) {
            return hexdec(substr($this->evil, $offset * 4, 4));
        }
    
        function offsetSet ( $offset , $value ) {
    
            $hex = dechex($value);
            if ($fill = 4 - strlen($hex)) {
                $hex = str_repeat("0",  $fill) . $hex;
            }
    
            for ($i=0; $i<4; $i++) {
                $this->evil[$offset*4+$i] = $hex[$i];
            }
        }
    
        function offsetUnset ( $offset ) {
            assert(false);
        }
    
    }
    

    So you can pretty much create an array object from this:

    $array = new IntegerstringArray();
    $array[2] = 65535;
    print $array[2];
    

    It internally stores a list and accepts 16-bit integers. The array offsets must be consecutive.

    Not tested. Just as an implementation guide.

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

Sidebar

Related Questions

Surfing the net I ran into Aquabrowser (no need to click, I'll post a
I'm trying to figure out a good way to go about this. Lets say
I dam trying to do this: http://docs.djangoproject.com/en/dev/topics/db/models/#be-careful-with-related-name Using this style This is saved as
I have the following action for a form. In the MyForm definition, I added
I've pushed my app to Heroku and now am trying to run '$ heroku
I have a community blog at thelazy.info . All things are working except the
I'm currently working on a project that's based on Android. Without getting into many
I'm trying to create a small app for users to have contacts. I'm using
I am building a blog-style application in Rails 3 where multiple users are able
I'm building a database that makes use of lots of many-to-many relations. For example,

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.