Using the stack and garbage collector?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using the stack and garbage collector?

abergel
Hi!

The following expression give me 102:
-=—=-=-=—=-=-=—=-=-=—=-=
old := Smalltalk vm parameterAt: 9.
15000 factorial.
new := Smalltalk vm parameterAt: 9.
new - old
-=—=-=-=—=-=-=—=-=-=—=-=

I find that surprising. Why is the garbage collector used if factorial solely use the stack?

Cheers,
Alexandre
--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply | Threaded
Open this post in threaded view
|

Re: Using the stack and garbage collector?

Sven Van Caekenberghe-2
15000! is a huge number, this computation involves large integer arithmetic. Large integers are allocated on the heap. Try a small number (to stay within Small integer range) and you'll see there is no GC activity.

BTW, the implementation of #factorial is not the correct algorithm when speed and efficient large integer arithmetic are required.

Please use the pharo-user ML for these kind of general questions.

> On 22 May 2016, at 20:12, Alexandre Bergel <[hidden email]> wrote:
>
> Hi!
>
> The following expression give me 102:
> -=—=-=-=—=-=-=—=-=-=—=-=
> old := Smalltalk vm parameterAt: 9.
> 15000 factorial.
> new := Smalltalk vm parameterAt: 9.
> new - old
> -=—=-=-=—=-=-=—=-=-=—=-=
>
> I find that surprising. Why is the garbage collector used if factorial solely use the stack?
>
> Cheers,
> Alexandre
> --
> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
> Alexandre Bergel  http://www.bergel.eu
> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Using the stack and garbage collector?

abergel
Very right! I should have guessed this.
Thanks!

Cheers,
Alexandre


> On May 22, 2016, at 3:46 PM, Sven Van Caekenberghe <[hidden email]> wrote:
>
> 15000! is a huge number, this computation involves large integer arithmetic. Large integers are allocated on the heap. Try a small number (to stay within Small integer range) and you'll see there is no GC activity.
>
> BTW, the implementation of #factorial is not the correct algorithm when speed and efficient large integer arithmetic are required.
>
> Please use the pharo-user ML for these kind of general questions.
>
>> On 22 May 2016, at 20:12, Alexandre Bergel <[hidden email]> wrote:
>>
>> Hi!
>>
>> The following expression give me 102:
>> -=—=-=-=—=-=-=—=-=-=—=-=
>> old := Smalltalk vm parameterAt: 9.
>> 15000 factorial.
>> new := Smalltalk vm parameterAt: 9.
>> new - old
>> -=—=-=-=—=-=-=—=-=-=—=-=
>>
>> I find that surprising. Why is the garbage collector used if factorial solely use the stack?
>>
>> Cheers,
>> Alexandre
>> --
>> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
>> Alexandre Bergel  http://www.bergel.eu
>> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
>>
>>
>>
>>
>
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.