Assuming I have a function that fills a buffer with binary data easily, how can I make that function return said buffer for further use?
The way I am currently doing it is by having it write the buffer (based off the content-length field from recv) write a temp file, then returning the name of that temp file so I can just read the tmp file into memory.
It would be nice however if I could just return the data directly rather than writing it to a tmp file, and using that. The only problem is if I return the binary data I have no way of knowing what the size of the buffer is (it’s not static) So my question is: is there a method of returning this binary data as well as maybe it’s size, or any way that I can work with it?
Or is my best bet just to stick with using tmp files?
In C you can either use a
structto encapsulate bunch of data items together, and pass that to your function, like:Or use value-return arguments, like: