[Python-ideas] Re: Trash bin

2020-09-26 Thread Eric V. Smith


On 9/25/2020 1:34 PM, Paul Bryan wrote:

On Fri, 2020-09-25 at 18:19 +0200, Marco Sulla wrote:

That I hope it's not the place where this proposal will be sent.
My idea is apparently simple: what if, anytime we create an object,
instead of deleting it, we send it in a trash bin? If the object is,
for some reason, recreated, we can take it from the trash bin. If
there is no more memory, the trash bin will be empty.
The problem is that, probably, args and kwargs used by object creation
must be stored. Maybe also copied? This could slow down the object
creation instead of speed it up? Could this be done by a separate
thread?
This would assume that said objects: a) are immutable and b) 
initialize to identical values for a given *args and **kwargs.


And if that's true, then the OP's purpose could be served by a function 
that uses collections.lru_cache() to generate their objects. The 
arguments would also have to be hashable, but if they're immutable then 
hashable is easy.


Eric

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/S5UMKXV72MI2UTH75CQKEUBF5DBXKFDQ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Trash bin

2020-09-25 Thread Paul Bryan
On Fri, 2020-09-25 at 18:19 +0200, Marco Sulla wrote:
> That I hope it's not the place where this proposal will be sent.
> 
> My idea is apparently simple: what if, anytime we create an object,
> instead of deleting it, we send it in a trash bin? If the object is,
> for some reason, recreated, we can take it from the trash bin. If
> there is no more memory, the trash bin will be empty.
> 
> The problem is that, probably, args and kwargs used by object creation
> must be stored. Maybe also copied? This could slow down the object
> creation instead of speed it up? Could this be done by a separate
> thread?

This would assume that said objects: a) are immutable and b) initialize
to identical values for a given *args and **kwargs.

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/62CXAQ5EFHODHNUD2V6YZS5ECBC75YKL/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Trash bin

2020-09-25 Thread Chris Angelico
On Sat, Sep 26, 2020 at 2:19 AM Marco Sulla
 wrote:
>
> That I hope it's not the place where this proposal will be sent.
>
> My idea is apparently simple: what if, anytime we create an object,
> instead of deleting it, we send it in a trash bin? If the object is,
> for some reason, recreated, we can take it from the trash bin. If
> there is no more memory, the trash bin will be empty.
>
> The problem is that, probably, args and kwargs used by object creation
> must be stored. Maybe also copied? This could slow down the object
> creation instead of speed it up? Could this be done by a separate
> thread?

This is actually the way certain objects ARE handled, but since memory
is allocated in chunks (not all objects are the same size), there are
in fact several "trash bins". They're called "free lists" and you can
explore the CPython source code if you're curious about how they work!

For info on free lists in general, Wikipedia might be of value:
https://en.wikipedia.org/wiki/Free_list

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/C6FF72U7PERWAOLYLXE2Q5LY557RGTKI/
Code of Conduct: http://python.org/psf/codeofconduct/