Does PHP 7.4 automatically optimize memory allocation?

Hi,

I'm trying to understand the impact of storing data in memory with PHP 7.4.

For example, if there is a non-empty array that is dynamically populated with data at the beginning of script execution, and that data seldom varies, and once stored in memory that data is not changed throughout the remainder of execution:

  • Does PHP allocate fresh memory for this array each time it receives a new request to execute the script?
    • E.g. What happens when there's 100 simultaneous requests for execution?
  • Are constants handled any differently in this respect?
  • How does this apply to multiple PHP server processes?
  • How does this apply to PHP-FPM?

Thanks!

πŸ‘︎ 19
πŸ’¬︎
πŸ‘€︎ u/whichpaul
πŸ“…︎ Dec 22 2021
🚨︎ report
Mod Ash addresses memory allocation limits in the Runescape Engine
πŸ‘︎ 6k
πŸ’¬︎
πŸ“…︎ Dec 16 2021
🚨︎ report
Programming languages without dynamic memory allocation?

Out of curiosity:

Has anyone here witnessed a somewhat general purposey language that doesn't allow dynamic allocations or at least stack-only allocations? (Not including Forths and old Fortran but including scripting languages of some sorts, that is.)

Follow-ups:

  • Do you have interesting ideas for specific features?
  • Do you have an intuition on what the overhead of dynamic memory allocation typically is?
πŸ‘︎ 37
πŸ’¬︎
πŸ‘€︎ u/Quecksilberbarren
πŸ“…︎ Jan 08 2022
🚨︎ report
Investigating Memory Allocations in Rust ysantos.com/blog/malloc-i…
πŸ‘︎ 61
πŸ’¬︎
πŸ‘€︎ u/y4kg72
πŸ“…︎ Jan 15 2022
🚨︎ report
Automatic Allocation Changes

Does wealthfront have any plans or option to shift investments to be more conservative as you get closer to retirement or a goals target date?

πŸ‘︎ 10
πŸ’¬︎
πŸ‘€︎ u/skrt123
πŸ“…︎ Nov 22 2021
🚨︎ report
I am a newbie in C coding, just wanted to verify if I have used the free() function correctly here. This is a code to scan and print a square matrix using dynamic memory allocation.

#include<stdio.h>
#include<stdlib.h>
int i,j;
int **readMatrix(int rows,int cols){
int **a;
a=(int**)malloc(rows*sizeof(int*));
for(i=0;i<rows;i++){
a[i]=(int*)malloc(cols*sizeof(int));
Β  Β  }
for(i=0;i<rows;i++){
for(j=0;j<cols;j++){
scanf("%d",&a[i][j]);
Β  Β  Β  Β  }
Β  Β  }
return a;
Β  Β  }
void displayMatrix(int **a,int rows,int cols){
for(i=0;i<rows;i++){
for(j=0;j<cols;j++){
printf("%d ",a[i][j]);
Β  Β  Β  Β  }
printf("\n");
Β  Β  }
}
int main(){
int n,**a;
scanf("%d",&n);
a=readMatrix(n,n);
displayMatrix(a,n,n);
for(i=0;i<n;i++){
free(a[i]);
Β  Β  }
free(a);
return 0;
}

πŸ‘︎ 7
πŸ’¬︎
πŸ‘€︎ u/sexytwink2
πŸ“…︎ Jan 12 2022
🚨︎ report
Dynamic allocation of memory for string input outputs more chars than expected?

I am trying to dynamically reallocate memory depending on the size of a user's string input, but my code is outputting a few more characters than expected. However, when I tried making some minor changes to a few lines (the lines commented out) it works perfectly fine:

Works fine (user inputs "test", allocates space for 4 + 1 ('\0') bytes, prints "test":

int main() {
    char* dyStr = dyn_strIn();
    puts(dyStr);    
    
    // OUTPUT:
    // test  // USER INPUT
    // test // PRINTED 

    return 0;
};

char *dyn_strIn()
{
    char *line = NULL, *tmp = NULL;
    size_t size = 0, index = 0;
    int ch = EOF; // EOF == -1

    while (ch) {
        ch = getc(stdin);

        /* Check if we need to stop. */
        if (ch == EOF || ch == '\n')
            ch = 0;

        /* Check if we need to expand. */
        if (size &lt;= index) {
            size += BLOCK_SIZE; // how much more space to allocate
            tmp = (char*)realloc(line, size);
            if (!tmp) {
                // could not reallocate
                free(line);
                line = NULL;
                break;
            }
            line = tmp;
        }

        /* Actually store the thing. */
        line[index++] = ch;
    }

    return line;
}

Outputs more chars than expected :

int main() {
    char* dyStr = dyn_strIn();
    puts(dyStr);    
    
    // OUTPUT:
    // test  // USER INPUT
    // test // PRINTED 
    // Β²Β²Β²Β² // PRINTED

    return 0;
};

char* dyn_strIn() {
    char* line = NULL, * tmp = NULL;
    size_t size = 0, index = 0;
    char ch = NULL;

    while (ch != '\n') {
        ch = getc(stdin);

        if (size &lt;= index) {
            // check if need to expand
            size += BLOCK_SIZE; // how much more space to allocate
            tmp = (char*)realloc(line, size); // assign line to temp in case line returns nullptr
            if (!tmp) {
                // could not reallocate
                free(line);
                line = NULL;
                break;
            }
            line = tmp;
        }
        line[index++] = ch;
    }

    return line;
}
πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/chandyego84
πŸ“…︎ Jan 04 2022
🚨︎ report
Am I doing memory allocation correctly? I am learning C++ and don't quite understand this concept. Not really asking for anybody to "fix" my code, I just wanted to know if this method is good.
πŸ‘︎ 71
πŸ’¬︎
πŸ‘€︎ u/MaybeAnonymousDev
πŸ“…︎ Dec 04 2021
🚨︎ report
Memory Allocation Without the GC, old but good jacksondunstan.com/articl…
πŸ‘︎ 5
πŸ’¬︎
πŸ“…︎ Jan 15 2022
🚨︎ report
There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (malloc) failed to allocate 1428816 bytes for Chunk::new

how can i fix it?

πŸ‘︎ 2
πŸ’¬︎
πŸ“…︎ Dec 28 2021
🚨︎ report
Will Panama allow the allocation of executable memory?

I was just wondering if this is something that has been discussed and discarded, or if discussion still has its place. As it is already possible to create a MemoryAddress from an arbitrary address, couldn't it make sense to be able to execute it?

πŸ‘︎ 11
πŸ’¬︎
πŸ‘€︎ u/TheMode911
πŸ“…︎ Nov 20 2021
🚨︎ report
NumPy Allocator - Configurable memory allocations in Python

Override NumPy's internal data memory routines using Python callback functions (ctypes).

Take a look at the test allocators for diverse use cases. (Tip: Get started with the test.debug_allocator!)

https://github.com/inaccel/numpy-allocator

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/eliaskoromilas
πŸ“…︎ Jan 06 2022
🚨︎ report
C++ Regular Array vs Dynamic Memory Allocation?

Hi guys, I'm learning C++ and I don't quite get the difference or the usefulness of dynamic array allocation. I wrote a short program that makes an array of both size and prints it out. Can you guys explain to me what the difference is and why I should use dynamic memory allocation (if true)?

#include &lt;iostream&gt;
void arrayMake();
void dynamicArrayMake();

int main()
{
    arrayMake();
    dynamicArrayMake();
    return 0;
}
//Input array size, make array, print [array]
void arrayMake()
{
    int arraySize = 1;
    std::cout &lt;&lt; "\nEnter array size: ";
    std::cin &gt;&gt; arraySize;
    int array[arraySize] = {0};

    for (int i: array)
        std::cout &lt;&lt; *(array+i);
}
//Input array size, make array, print [dynamic memory array]
void dynamicArrayMake()
{
    int arraySize = 1;
    std::cout &lt;&lt; "\nEnter array size: ";
    std::cin &gt;&gt; arraySize;
    int* dynamicArray = new int[arraySize];

    for (int i = 0; i &lt; arraySize; i++)
        std::cout &lt;&lt; *(dynamicArray+i);
}
πŸ‘︎ 6
πŸ’¬︎
πŸ‘€︎ u/Anthonyy232
πŸ“…︎ Nov 16 2021
🚨︎ report
please help memory allocation
πŸ‘︎ 67
πŸ’¬︎
πŸ‘€︎ u/PrO_BattoR
πŸ“…︎ Oct 26 2021
🚨︎ report
Is it possible to pass an automatically allocated array to a function to enumerate its elements using dynamic memory allocation?

The title might be confusing so let me just show you what I'm trying to do:

Say I have a function

Status enumerate_things(const char* all_the_things, int* extractable, char** to_extract_to[])

which takes in a rather long string (all_the_things) and set extractable to a number of elements (in this example substrings of all_the_things) the function is able to extract and an array of strings to extract those substrings into (to_extract_to[]).

And if to_extract_to is set to NULL, it'll just populate extractable and not proceed further.

The idea is to call the function twice to safely allocate an array to extract those substring into.

For example if enumerate_things was a function that would split a string on space character, this is how I'd want to use it.

int main()
{

  int number_of_substring = 0;
  const char* some_string = "this is an example string";

  enumerate_things(some_string, &amp;number_of_substring, NULL);

  char* list_of_substrings[number_of_substring];

  enumerate_things(some_string, &amp;number_of_substring, &amp;list_of_substrings);

  // do some stuff
  // some more stuff
  // ...
  // ...

  // Now that all things are done, free the allocated memory.

  for (int i = 0; i &lt; number_of_substring; ++i)
    {
      if (list_of_substrings[i])
        free(list_of_substrings[i]);
    }
}

internally enumerate_things will have a loop like this one

  for (int i = 0; i &lt; number_of_substring; ++i)
    {
      (*to_extrat_to)[i] = malloc(sizeof(char) * length_of_substring);
      strncpy((*to_extrat_to)[i], substring, sizeof(char) * length_of_substring);
    }

The problem is that these lines don't work

  char* list_of_substrings[number_of_substring];
  enumerate_things(some_string, &amp;number_of_substring, &amp;list_of_substrings);

The warning I get is this

Incompatible pointer types passing 'char * (*)[number_of_substring]' to parameter of type 'char***'.

The easiest fix I found is this

  char** list_of_substrings = NULL;
  list_of_substrings = malloc(sizeof(char*) * number_of_substring);
  enumerate_things(some_string, &amp;number_of_substring, &amp;list_of_substrings);

But I want to avoid using malloc there. Would that be possible?

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/ioov
πŸ“…︎ May 03 2020
🚨︎ report
.NET Memory poster - generations and allocation budget
πŸ‘︎ 71
πŸ’¬︎
πŸ‘€︎ u/konradkokosa
πŸ“…︎ Oct 08 2021
🚨︎ report
.NET Memory poster - generations and allocation budget
πŸ‘︎ 108
πŸ’¬︎
πŸ‘€︎ u/konradkokosa
πŸ“…︎ Oct 08 2021
🚨︎ report
Memory allocation/reassignment with ownership change

Hello,

Perhaps not necessary to know but interesting nonetheless. Apologies - on my phone so no code examples or pictures.

If I create a struct, which then exists in memory, and I then pass ownership of it to another struct(or a Vec, etc) will the entire thing be moved to be in the memory location assigned to the owning struct, or does Rust optimise the move away and effectively create a pointer?.

If the former, I assume that it's then significantly more efficient to pass around &/&mut s than actual objects even if you did want to transfer ownership?

If the latter, how does Rust treat that pointer in comparison to a &mut ?

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/teddie_moto
πŸ“…︎ Nov 30 2021
🚨︎ report
Sectech Ages - Memory allocation filling up way too fast!

Greetings! So my Minecraft game is constantly seizing up due to the game filling up its allocated memory Way too fast. It originated when I got to a certain point of progression in the game but despite my setup, it's still giving me issues. it makes the game completely unplayable.

Here is a screenshot of specs

I've tried transferring the game save to GL launcher as I read that overwolf can cause that problem, but it didn't fix the issue. I also am using the recommended java arguments that Darkosto posted for the pack here. I'm not sure if I'm allocating too little ram or not enough at 8Gb, as I've got 2x8GB sticks OC @ 3200. Maybe it's a config issue or is my game just way too big to play anymore? If anyone could give me some guidance on this issue it would be much appreciated! I've put way too many hours into this world.

πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/aragojj7418
πŸ“…︎ Nov 19 2021
🚨︎ report
Detect your application’s memory under-allocation in a proactive manner youtube.com/watch?v=btnI7…
πŸ‘︎ 8
πŸ’¬︎
πŸ‘€︎ u/mike_jack
πŸ“…︎ Dec 02 2021
🚨︎ report
Dynamic Memory Allocation in C

ptr = (int*)malloc(5*sizeof(int));

if a allocate 5*size(int) to ptr, do I give to ptr 20 addresses to work on? and how the pointer keeps tracking the addresses given, coz the addresses can't be like *****1,*****2,*****3,... so they gonna be in different places on the memory or am wrong?

πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/who_not
πŸ“…︎ Oct 09 2021
🚨︎ report
DLL Hollowing - This variant of memory allocation removes the prerequisite of having write access to the target DLL (in contrast to Phantom DLL Hollowing) and is stealthier than β€œclassic” Dll Hollowing (which uses the LoadlLibrary API) as we keep the benefits of storing the payload in a legit DLL secforce.com/blog/dll-hol…
πŸ‘︎ 11
πŸ’¬︎
πŸ‘€︎ u/digicat
πŸ“…︎ Nov 22 2021
🚨︎ report
How does wasm-bindgen manage memory allocation?

Given that wasm-bindgen, itself, doesn’t use the standard library, how does it let code that uses it allocate memory (ie use Box and related heap allocations)? I don’t see anything in its codebase that defines a custom global allocator.

I’m new to Rust but don’t understand quite understand how that’s happening.

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/aunyks
πŸ“…︎ Nov 17 2021
🚨︎ report
Reached heap limit Allocation failed - JavaScript heap out of memory

Hello everyone I am having this error when I try to build/dev my Next.js app. Need help thanks!

Here's the error code

&lt;--- Last few GCs ---&gt;

[8596:00000230EE25E700]    72717 ms: Scavenge (reduce) 2045.8 (2081.2) -&gt; 2045.7 (2081.9) MB, 4.4 / 0.0 ms  (average mu = 0.246, current mu = 0.138) allocation failure
[8596:00000230EE25E700]    75691 ms: Mark-sweep (reduce) 2046.5 (2081.9) -&gt; 2046.3 (2082.7) MB, 2575.9 / 0.0 ms  (+ 49.8 ms in 13 steps since start of marking, biggest step 7.4 ms, walltime since start of marking 2633 ms) (average mu = 0.185, current mu =

&lt;--- JS stacktrace ---&gt;

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF667B0FDCF v8::internal::CodeObjectRegistry::~CodeObjectRegistry+112495
2: 00007FF667A9EF86 DSA_meth_get_flags+65526
3: 00007FF667A9FE3D node::OnFatalError+301
4: 00007FF6683D167E v8::Isolate::ReportExternalAllocationLimitReached+94
5: 00007FF6683BBB5D v8::SharedArrayBuffer::Externalize+781
6: 00007FF66825F2AC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468
7: 00007FF66825C3E4 v8::internal::Heap::CollectGarbage+4244
8: 00007FF668259D60 v8::internal::Heap::AllocateExternalBackingStore+2000
9: 00007FF66827E696 v8::internal::Factory::NewFillerObject+214
10: 00007FF667FB1965 v8::internal::DateCache::Weekday+1797
11: 00007FF66845F071 v8::internal::SetupIsolateDelegate::SetupHeap+494417
12: 00000230F06B2EB5
πŸ‘︎ 3
πŸ’¬︎
πŸ“…︎ Oct 29 2021
🚨︎ report
Nothing has changed in a significant way since 1996 [...] If you're an old school C programmer who knows how pointer arithmetic and memory allocation works, you're better than 99% of the total trash new-school Node.js/Django/Rails/React developers who think JSX is some sort of "innovation" news.ycombinator.com/item…
πŸ‘︎ 100
πŸ’¬︎
πŸ‘€︎ u/tomwhoiscontrary
πŸ“…︎ Aug 01 2021
🚨︎ report
new allocation assigned to automatic variable β€” is that a leak?

Will the memory referred to by the automatic variable automatic_int be destroyed when that variable goes out of scope, even though the memory was originally allocated using ` new `?

When I ran this code, I got the expected error:

'automatic_int' was not declared in this scope

but was the memory allocated here still allocated β€” a memory leak?

automatic_int = allocate_int(3);

The code:

int allocate_int()
{
    int* new_int = new int(3);
    return *new_int;
}

int main()
{
    {
        int automatic_int = 5;
        automatic_int = allocate_int();
    }

    std::cout &lt;&lt; automatic_int &lt;&lt; std::endl; // Error here

    // Do more stuff...

    return 0;
}

Thanks in advance

Also, regarding markup, how come my backticks for inline code don't seem to ever work? (See the word new on the second line of this post.) This is the method that the websites tell me to use. Am I not doing it right? Is there another, better method?

EDIT: typo

πŸ‘︎ 4
πŸ’¬︎
πŸ‘€︎ u/goodgamin
πŸ“…︎ May 24 2021
🚨︎ report
NumPy Allocator - Configurable memory allocations in Python

Override NumPy's internal data memory routines using Python callback functions (ctypes).

Take a look at the test allocators for diverse use cases. (Tip: Get started with the test.debug_allocator!)

https://github.com/inaccel/numpy-allocator

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/eliaskoromilas
πŸ“…︎ Jan 06 2022
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.