Skip to content

Conversation

@v923z
Copy link
Owner

@v923z v923z commented Apr 18, 2022

This PR addresses the issue raised in #520

@v923z v923z linked an issue Apr 18, 2022 that may be closed by this pull request
code/ndarray.c Outdated
size_t *coords = m_new0(size_t, ndim);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(coords, 0, ndim*sizeof(size_t));
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to use both m_new9 and MICROPY_GC_CONSERVATIVE_CLEAR. You can select one of these options:

size_t *coords = m_new0(size_t, ndim);

or:

size_t *coords = m_new(size_t, ndim);
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(coords, 0, ndim*sizeof(size_t));
#endif

Have a look at the source code of m_malloc0 to understand better.

The first option (just call m_new0) is much simpler and I suggest to do that. The API of m_new0 is unlikely to change. But the macro MICROPY_GC_CONSERVATIVE_CLEAR may one day be removed.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have obviously tanked it completely. Thanks for pointing this out!

@v923z v923z merged commit 53bc8d6 into master Apr 22, 2022
@v923z v923z deleted the memset branch April 22, 2022 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OPTIMISATION] Only clear ndarray data once when it's allocated

3 participants