Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Memory reusability

by rovf (Priest)
on Aug 12, 2009 at 09:12 UTC ( [id://787886]=note: print w/replies, xml ) Need Help??


in reply to Memory reusability

From the viewpoint of language definition of Perl, there is nothing which dictates that memory must be reused, though an implementation of Perl, which does not free memory, would hardly be useful except for the most simple tasks. So I would say: The question whether "Perl" (as a language) reuses memory, is meaningless, but all existing Perl implementations certainly re-use memory. Of course this does not mean that part of the memory not used by Perl, automatically can be used by other application. This question belongs to the architecture of the undrelying OS, and is not related to Perl.

can't I free a memory and assign to some other ?
Yes and no. You can not force Perl to re-use memory in a way you dictate (and I don't see a reason why you would want to anyway), but memory is re-used automatically, on the fly. For instance, in the following program
my $a='abcd'; ... $a='efgh';
the space occupied by the string 'abcd' is not lost, but will eventually be used later on for something different.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^2: Memory reusability
by JavaFan (Canon) on Aug 12, 2009 at 11:53 UTC
    Of course this does not mean that part of the memory not used by Perl, automatically can be used by other application. This question belongs to the architecture of the undrelying OS, and is not related to Perl.
    That's not entirely true. Certainly, whether or not the OS is able to accept memory back from the OS isn't related to perl. But if perl runs on an OS that does allow for processes to return memory back to the OS during the lifetime of the process, then it becomes related to perl. Because then perl would actually have to make the appropriate system calls to give memory back.
      then it becomes related to perl.

      Thank you for clarification. To be more precise: It becomes related to the Perl implementation (not to Perl as a language), i.e. ActiveState Perl could do it one way and Strawberry Perl could do it another way.

      -- 
      Ronald Fischer <ynnor@mm.st>
      Because then perl would actually have to make the appropriate system calls to give memory back.

      Perl should just use standard free(3) function and this function will make appropriate system call to return memory to OS.

        Whether free(3) returns memory depends on the OS. And whether perl calls free(3) depends on whether you build perl with its own malloc implementation, or whether it's using the system one. Which one is used depends on the setting of the usemymalloc configuration flag, and, in the absence of the flag, whatever hint is set for your OS in the hints directory.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://787886]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-24 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found