Efficient 2 pass using heap memory

92 views Asked by At

I have an algorithm that requires making two passes a file's data. The file may be stdin or stream (like a |) since this is a command line tool, which makes me unfortunately (to the best of my knowledge) rule out mmap.

I require the information from the 1st pass in order to perform a write operation on the 2nd pass. This is because I need a sum of all the bytes on the first pass for a specific cipher on the second pass.

One way I have thought of to do this is to use the heap as a single contiguous region of memory, and to allocate additional size once the end has been reached with sbrk (similar to what I believe the first implementation of bash) did. Is there a simple way to do this?

Specifically, how can I avoid stdlib's set-up of the heap and do so myself?

0

There are 0 answers