Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ephraimfeldblum
Copy link
Contributor

@ephraimfeldblum ephraimfeldblum commented Apr 6, 2025

void mr_BufferWriterRewind(mr_BufferWriter* bw) {
bw->buff->size = 0;
bw->buff->cap = DEFAULT_INITIAL_CAP;
bw->buff->buff = MR_REALLOC(bw->buff->buff, DEFAULT_INITIAL_CAP);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to avoid reuse of the DEFAULT_INITIAL_CAP and use bw->buff->cap here instead.

Also, a question: who frees this buffer? Are there scenarios we get here with an already-allocated buff and can cause a leak?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, no need to realloc the buffer at all.

creation and destruction of buffers should be handled by libMR, the user doesn't need concern themselves with it. aside from that, i'm not sure i understand the question. realloc frees the old allocation if it determines to move to a larger allocation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I misread it as MR_ALLOC()...

@ephraimfeldblum ephraimfeldblum merged commit 3b85338 into master Apr 9, 2025
7 checks passed
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.

2 participants