Memory managment in init_stream (init_bitstream on feat/api branch) and terminate stream. #36
Labels
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TOPIO/BigWhoop#36
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The functions
init_bitstream
andterminate_stream
respectively allocate and reallocate the bitstream->memory depending on whether a NULL is passed intoinit_bitstream
and if theL
andLmax
differ interminate_stream
.Now, given the newer API on the feat/api branch, in which the user provides a pointer to buffer the (de-)compression output, the behavior of
terminate_stream
might lead to reallocating the user-provided pointer.A simpler and safer approach should be chosen for both function possibly following RAII or other memory managment schemes as suggested here: https://www.rfleury.com/p/untangling-lifetimes-the-arena-allocator
PR #41
Reallocation of the memory block should only happen during code-stream and header assembly (AFAIK). Are we going to use the memory block provided by the user to initialize the respective bit-streams?
AFAYK. Yes, you are right. The user output memory is used to initialize a
bitstream
during decompression. (See363846202b/src/library/codestream.c (L1398)
) So, only the header assembly in tier2 requires allocation (363846202b/src/library/tier2.c (L485)
). An option is to pull it out and pass the locally allocated memory into theinit_stream
. It would be preferable in the sense of SRP.For
terminate_stream
, an equivalent solution that separates freeing the memory from passing it on to the packed stream would be possible. SRP would clarify memory management.Additionally, looking into this revealed that type
bitstream
instances are local in function scope. Dynamic allocation and pointer-value semantics could be omitted. Then, there would be no allocation to deal with bitstreams whatsoever.Can be closed after #41 was merged.