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

Investigate first figuring out how many messages will fit, and then allocating a buffer large enough #18

Open
cer opened this issue Jan 7, 2020 · 0 comments
Assignees

Comments

@cer
Copy link
Contributor

cer commented Jan 7, 2020

Currently, the buffer is dynamically reallocated.
An alternative approach is

  1. Figure out how many messages will fit in the buffer
  2. Allocate a big enough buffer
  3. Deserialize the messages into it

The trick is to perform step 1 without allocating memory, .e.g calculating the size in bytes of a String without calling getBytes(encoding). Note, it would be ok to overestimate the needed size, e.g. assume each char in string needs 2 bytes.

This needs research:, e.g. https://stackoverflow.com/questions/19852460/get-size-of-string-w-encoding-in-bytes-without-converting-to-byte

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