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

FastBuffer::resize will not resize below 200 #15

Closed
Karsten1987 opened this issue Apr 18, 2018 · 3 comments
Closed

FastBuffer::resize will not resize below 200 #15

Karsten1987 opened this issue Apr 18, 2018 · 3 comments

Comments

@Karsten1987
Copy link
Contributor

Karsten1987 commented Apr 18, 2018

Connects to ros2/demos#185

I wonder why the implementation of FastBuffer::resize can't resize an empty buffer below 200.
https://github.com/eProsima/Fast-CDR/blob/master/src/cpp/FastBuffer.cpp#L45-L81

If I have an empty buffer and want to resize it to an exact number of size - let's say I know how much data I want to copy into it - the minimum size of it is BUFFER_START_LENGTH, which is hard set to 200
https://github.com/eProsima/Fast-CDR/blob/master/src/cpp/FastBuffer.cpp#L23

why is that?

@richiware
Copy link
Member

FastBuffer class can handle a user's buffer (char*) or an internal buffer. Usually I use the first approach. I know the length of my serialized data and I give a buffer to FastBuffer.

The second approach was useful if user doesn't know the length of the serialized data and doesn't want to precaculate it. We select to start with 200bytes. Cdr starts serializing and when the internal buffer size is insufficient, it will reallocate more and continue serializing.

@Karsten1987
Copy link
Contributor Author

I understand. However, this requires that the memory for the buffer is managed externally. That is to alloc and de-allocate the external buffer.
With the referenced reserve function, the buffer could stay internally and the destructor of the class can conveniently cleanup the allocated memory.

@Karsten1987
Copy link
Contributor Author

closed by e986a9e

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

2 participants