Michael G Schwern <[EMAIL PROTECTED]> writes:

> On Thu, Oct 03, 2002 at 10:43:43AM +0100, Nicholas Clark wrote:
> > The reason I'm saying it might not be much use to people unfamiliar with
> > the internals of unix is precisely because it does return a precisely defined
> > but not directly useful value - the highest address on the heap.
> > If you read it, call perl code that creates a known perl structure, and read
> > it again, doesn't go up directly and exactly related to the amount of memory
> > that structure needed. Depending on how much other memory there is free, it
> > may not go up at all, or it may go up more if the allocation system grabs a
> > big block of free space.
> 
> Ok, now I'm really confused.
> 
> - sbrk() returns, effectively, the size of the heap.
> - the heap may not go up when you create a perl structure

That's true. There may be formerly-used and now free memory in the
"heap" which can be reused.

> 
> but MemUsed() is shown to be used like this:
> 
>         use Devel::Internals;
>       
>       my @array = (1..10000);
>         MemUsed "creation of array";         
>       my @dup = @array;
>         MemUsed "duplication of array";
> 
> and MemUsed, in scalar context, returns the sbrk value, the size of the
> heap.  So I presume in the above code it simply returns the difference
> between the sbrk value between the two calls.  But Nick just said this isn't
> actually the memory used, it's just the different in heap size.  But the
> function is called MemUsed!

Well, it won't return the amount of memory for newly-created perl
structures, but it should reflect the amount of memory the perl
process takes from the operating system's virtual memory system. Hence
the name MemUsed seems OK to me. For other systems which do not use
sbrk(), MemUsed should be implemented differently.

Regards,
        Slaven

-- 
Slaven Rezic - [EMAIL PROTECTED]

    tknotes - A knotes clone, written in Perl/Tk.
    http://ptktools.sourceforge.net/#tknotes

Reply via email to