jwerle / b64.c

Base64 encode/decode
MIT License
269 stars 103 forks source link

Static buffers implementation #16

Open d21d3q opened 7 years ago

d21d3q commented 7 years ago

How about making this library able to use static buffers? I am playing with them now on this branch. For now I've added b64_encode_static because it has different parameters set, but ideally would be to make one entry point with optional (nullable) parameter for output buffer, so b64_encode would look like this. Another thing would be introduce some macro (eg B64_STATIC_BUFFERS_ONLY) which would exclude code for dynamic memory allocation. Have a look at nanopb library. Quite big, but in can run both with dynamic memory allocation and without (excluded at compilation time).

Motivation for this is performance improvement - I am currently making project which is translating some serial protocol into another (with human readable frames) so that calling malloc and free for every single incoming byte seems to be overhead for this task.

jwerle commented 7 years ago

@d21d3q looks good!

d21d3q commented 7 years ago

So you don't mind breaking backward compatibility? On the other hand incrementing major version number will do the job.

jwerle commented 7 years ago

@d21d3q in this case, no I do not. The less malloc calls this implementation can make, the better