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

PoolBuffers::endBuffer Strategy issue #21

Closed
chrislong2015 opened this issue Aug 28, 2015 · 6 comments
Closed

PoolBuffers::endBuffer Strategy issue #21

chrislong2015 opened this issue Aug 28, 2015 · 6 comments

Comments

@chrislong2015
Copy link

1、void PoolBuffers::endBuffer(Buffer* pBuffer) const {
2、 if (pBuffer->capacity() > _maximumCapacity) {
3、 delete pBuffer;
4、 return;
5、 }
6、 pBuffer->clear(); //to fix clip, and resize to 0
......
}

should we take line 6 before line 2?

@reatailret
Copy link

"return" on line 4 .

@chrislong2015
Copy link
Author

line 2: the capacity maybe not the real capacity,it can have been changed by clip()?

@MathieuPOUX
Copy link
Contributor

Hi,

I had a algo redesign for PoolBuffers/PoolBuffer that I share now by this last commit =>
5f92bb2
Works a lot better, let me know if it solves your memory issue.
+

@chrislong2015
Copy link
Author

Hi,
I think it still has a problem, because of the possible clip(), _capacity would have been changed.

1、
void Buffer::clip(UInt32 offset) {
if (offset > _size)
offset = _size;
if (offset == 0)
return;
_offset += offset;
_data += offset;
_size -= offset;
_capacity -= offset;
}

2、
UInt32 capacity() const { return _capacity; }

3、
void release() { if (!_pBuffer) return; poolBuffers.endBuffer(_pBuffer); _pBuffer = NULL; }

4、
void PoolBuffers::endBuffer(Buffer* pBuffer) const {
lock_guard lock(_mutex);
_buffers.emplace(pBuffer->capacity(),pBuffer);
}

@MathieuPOUX
Copy link
Contributor

Yes you are right, on my next commit I will solve it by the following fix:

void PoolBuffers::endBuffer(Buffer* pBuffer) const {
pBuffer->clear();
lock_guard lock(_mutex);
_buffers.emplace(pBuffer->capacity(),pBuffer);
}

Thanks

@chrislong2015
Copy link
Author

Thanks! I think it will work better now!

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

4 participants