Hey I would like to understand why we call memset at:
https://github.com/micropython/micropyt ... ray.c#L189
I thought the GC in both modes:
(MICROPY_GC_CONSERVATIVE_CLEAR/0)
https://github.com/micropython/micropyt ... /gc.c#L483
Should clear the memory already - am I wrong here?
Thanks!
Sam
redundant memset?
Re: redundant memset?
I suspect its history of how the code has evolved.
I'm pretty sure that gc_alloc didn't used to do a memset, and it was added because there were certain cases where it would cause memory to not be freed it that wasn't being done.
Allocating a bytearray needs to guarantee that the contents are zero'd.
I suspect that if you're running into performance issues because of this then you're allocating too many bytearrays and should be looking at using memoryview and/or methods like read_into.
I'm pretty sure that gc_alloc didn't used to do a memset, and it was added because there were certain cases where it would cause memory to not be freed it that wasn't being done.
Allocating a bytearray needs to guarantee that the contents are zero'd.
I suspect that if you're running into performance issues because of this then you're allocating too many bytearrays and should be looking at using memoryview and/or methods like read_into.
Re: redundant memset?
Thanks, actually no - not running into performance issues - just have a "memory problem" in my code (opened a new thread for that) which got me thinking maybe I should memset 0 after every m_alloc - to remove trash which might be a reference to the heap - the memset in bytearray spooked me into thinking that..., guess "missing" memsets are not my problemdhylands wrote:I suspect its history of how the code has evolved.
I'm pretty sure that gc_alloc didn't used to do a memset, and it was added because there were certain cases where it would cause memory to not be freed it that wasn't being done.
Allocating a bytearray needs to guarantee that the contents are zero'd.
I suspect that if you're running into performance issues because of this then you're allocating too many bytearrays and should be looking at using memoryview and/or methods like read_into.