On Mon, Dec 22, 2008 at 12:36 PM, Patrick Kirsch
<pkir...@bookandsmile.de> wrote:
> Mr. Shawn H. Corey schrieb:
>> On Mon, 2008-12-22 at 18:10 +0100, Patrick Kirsch wrote:
>>
>>> Is there a possibility to influence it, to free memory (in the sense
>>> of
>>> give it back to the OS)?
>>>
>>>
>>
>> Does your OS have a function that allows processes to return memory to
>> it?  Many do not.  Most of the time, when a process frees memory, it can
>> only re-use it itself.
>>
>>
> I'm using: Linux 2.6.27.6 #2 SMP x86_64; Distribution: OpenSUSE 11.0 .
> In my opinion the Linux kernel is/should be able to rearrange freed
> memory between processes (I think e.g. of the slab).
>
> But let me show another example:
> $foo = 'X' x 100000000;
> getc;
> undef $foo;
> getc;
> $foo2 = 'X' x 100000000;
> getc;
>
> gives (again output from 'ps auxwf'):
> user   15185 18.0  4.8 211000 197020 pts/5
> user   15185  5.0  2.4 113340 99364 pts/5
> user   15185  4.3  7.2 308660 294684 pts/5
>
> As you see some RAM is given back to the OS (~50%, [99364/197020]) .
> BUT: I would expect that the Perl virtual machine (memory management)
> reuses the allocated RAM from $foo for $foo2.
> As you see $foo is not used anymore in the program context, but the
> memory management still holds some RAM for it present (I mean why :-) ?
> ). As my education is C, I would not expect this behavior.
>
> Thanks,

Hi Patrick,

This is hardly a beginner question, and as such is a bit out of scope
for this list. If you're really interested in Perl internals, you'll
probably want to check out the alt.lang.perl.misc newsgroup.

The real question, though, is why do you care. One of main advantages
of Perl over other programming languages it its approach to automatic
memory allocation and garbage collection. That variables are
abstracted from memory location, and that the the programmer doesn't
ever have to deal with malloc() and free() calls is, in most people's
opinion, one of Perl's strongest selling points. That Perl normally
allocates more memory than it needs in order to speed up string
concantenation and list expansion is usually considered a feature,
too.

If you are programming in an environment where performing memory
deallocation in real time concureently with variable de-initialization
is important for some reason, though, googling "perl internals" will
turn up some useful results that you can use as a jumping off point
for posting some specific questions on alt.lang.perl.misc and/or the
Perl Monks site.

If there are only specific variables or specific parts of your program
that are of concern, though, you might just want to investigate the XS
interface (`perldoc perlxs`), or the Inline::C module.

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to