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

Meaning of _used member in Poco::Buffer #760

Closed
DBarzo opened this issue Mar 27, 2015 · 2 comments
Closed

Meaning of _used member in Poco::Buffer #760

DBarzo opened this issue Mar 27, 2015 · 2 comments
Labels

Comments

@DBarzo
Copy link

DBarzo commented Mar 27, 2015

Hi,

If I have not misunderstood, the _used member in Poco::Buffer should contains the number of 'valid' data into the buffer.
But, if so, I have some doubts.
In some situation, it has the same meaning of 'capacity'...

For example, in the constructor:

Poco::Buffer<UINT8> _buffer(100); // _used is initialized to 100
bool is_empty = _buffer.empty();  // Return FALSE!

or using the clear() method:

Poco::Buffer<UINT8> _buffer(100);
_buffer.append(_data);
_buffer.clear();   // _used is not cleared
bool is_empty = _buffer.empty();  // Return FALSE!

Is this the desired behavior?

Of course I could have a buffer with all "valid" '0' but, in this case I will use the ctor:

Buffer(T* pMem, std::size_t length)

where _used is correctly valorized.

Daniele.

@aleks-f
Copy link
Member

aleks-f commented Mar 27, 2015

When empty() is true, it means the size of used data in buffer is zero. _used is the valid (used) size, see Buffer::size(). Calling clear() zeroes the used memory but does not empty the buffer. There may be a difference between used and capacity because, after the buffer is shrunk to smaller capacity, unused memory is not deallocated, see resize() and setCapacity()

@DBarzo
Copy link
Author

DBarzo commented Mar 27, 2015

Hi Alex,
thanks for the reply.
I change my code from my_buffer.clear() to my_buffer.resize(0) to 'destroy' (or 'invalidate') the buffer, I don't have found another way to do it 😄

@DBarzo DBarzo closed this as completed Mar 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants