Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NCNN_XADD should return int #538

Closed
00liujj opened this issue Aug 23, 2018 · 6 comments
Closed

NCNN_XADD should return int #538

00liujj opened this issue Aug 23, 2018 · 6 comments

Comments

@00liujj
Copy link
Contributor

00liujj commented Aug 23, 2018

static inline void NCNN_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; }

@nihui nihui closed this as completed in 9e49144 Aug 23, 2018
@PapaMadeleine2022
Copy link

do not understand this function. return tmp? rather than *addr

@nihui
Copy link
Member

nihui commented Jan 22, 2020

That is how compare and exchange works.

@PapaMadeleine2022
Copy link

@nihui Thanks. Another confusing place. Let refcount pointer point the last+1 position(last position is for the last item of the Mat) ?

@nihui
Copy link
Member

nihui commented Jan 22, 2020

It is fine to make the refcount integer live on its own memory heap.
When the memory is allocated, the mat content data and refcount are allocated together.
We do this as we can save one malloc invocation, resulting less heap fragments.

@PapaMadeleine2022
Copy link

PapaMadeleine2022 commented Feb 3, 2020

@00liujj thanks.

That is how compare and exchange works.

When I see the line here, I finally understand the meaning of NCNN_XADD function. This design is great! Thanks.

@PapaMadeleine2022
Copy link

It is fine to make the refcount integer live on its own memory heap.
When the memory is allocated, the mat content data and refcount are allocated together.
We do this as we can save one malloc invocation, resulting less heap fragments.

thanks for your explanation.

This issue was closed.
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

No branches or pull requests

3 participants