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

This is relation to my other post but it is a different scenario. When
There is an interesting post over here about this, in relation to cross-application flow
In following php code in here //print_r($reunits); is output this: http://pastebin.com/RbqZ5kHV but in here
In relation to this post I'm using the MvcSiteMap provider. I can't seem to
This is my first post here, therefore apologize for any blunders. I'm developing a
I want to create a invoice as described in this post here . I
My question is in relation this this answer. https://stackoverflow.com/a/8773953/1297775 I have read at many
This is in relation to latest Juno or 4.2 release of Eclipse . I
In relation to this stackoverflow question , how would I go about creating my
In relation to this question ( Efficient hashCode() implementation ) I have one more

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.