Avoid reallocation in emit_bit #39

Open
opened 2024-07-02 13:55:56 +00:00 by Gregor Weiss · 1 comment
Collaborator

We could spare the reallocation in emit_bit if the stream is guaranteed to have the correct size. The only usage of emit_bit is taking the header variable in create_packet of tier2. The memory of header is initially allocated to PACKET_HEADER_SIZE=512.

A test that used two times the PACKET_HEADER_SIZE could avoid reallocation in emit_bit.

Generally, PACKET_HEADER_SIZE is variable and would have to be calculated to avoid dynamic reallocation.

How could we do such a calculation?

We could spare the reallocation in `emit_bit` if the `stream` is guaranteed to have the correct size. The only usage of `emit_bit` is taking the `header` variable in `create_packet` of tier2. The `memory` of `header` is initially allocated to PACKET_HEADER_SIZE=512. A test that used two times the `PACKET_HEADER_SIZE` could avoid reallocation in `emit_bit`. Generally, `PACKET_HEADER_SIZE` is variable and would have to be calculated to avoid dynamic reallocation. How could we do such a calculation?
Gregor Weiss added this to the Maintainbarkeit project 2024-07-02 13:55:56 +00:00
Gregor Weiss changed title from Avoid reallocation in emit_bit to Avoid reallocation in `emit_bit` 2024-07-02 13:56:42 +00:00

In principal the max. header size should have an upper limit for a precinct of maximum size and number of codeblocks where every codeblock contributes to that packet. I'd have to check if that is actually the case but if true we could simply allocate a MAX_PACKET_HEADER_SIZE and reallocate once the header has been assembled. Alternatively we could forgo the reallocation and simply write out the packet header portion of the allocated memory block to the codestream once it is needed. However this would increase the memory footprint of the library.

In principal the max. header size should have an upper limit for a precinct of maximum size and number of codeblocks where every codeblock contributes to that packet. I'd have to check if that is actually the case but if true we could simply allocate a MAX_PACKET_HEADER_SIZE and reallocate once the header has been assembled. Alternatively we could forgo the reallocation and simply write out the packet header portion of the allocated memory block to the codestream once it is needed. However this would increase the memory footprint of the library.
Sign in to join this conversation.
No labels
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TOPIO/BigWhoop#39
No description provided.