redundant memset?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
sameid
Posts: 11
Joined: Mon Feb 27, 2017 7:30 am

redundant memset?

Post by sameid » Wed Apr 05, 2017 7:40 pm

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

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: redundant memset?

Post by dhylands » Thu Apr 06, 2017 12:14 am

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.

sameid
Posts: 11
Joined: Mon Feb 27, 2017 7:30 am

Re: redundant memset?

Post by sameid » Fri Apr 07, 2017 8:32 pm

dhylands 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.
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 problem

Post Reply