For example, the base64 api's have a user pass in a dst array to decode into. The nacl API's in golang.org/x/crypto follow a similar pattern.
The advantage of doing it this way is that it reduces allocations, which helps performance.
The disadvantage is that it requires the caller to know more about how the API works, and ensure they bring along a byte array that's large enough.
The C/C++ API's have it both ways. The C++ API's return a byte array, the C API's require you to pass one in, but I think the latter is because you can only return integers from C functions..
For example, the base64 api's have a user pass in a
dstarray to decode into. The nacl API's in golang.org/x/crypto follow a similar pattern.The advantage of doing it this way is that it reduces allocations, which helps performance.
The disadvantage is that it requires the caller to know more about how the API works, and ensure they bring along a byte array that's large enough.
The C/C++ API's have it both ways. The C++ API's return a byte array, the C API's require you to pass one in, but I think the latter is because you can only return integers from C functions..