Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Growable buffer for plain C [closed]

I need an open-source (preferably MIT-licensed) light-weight growable buffer implemented in plain C (preferably also compileable as C++).

I need API equivalent to following (pseudo-code):

  • void set_allocator(buffer * buf, allocator_Fn fn);
  • void push_bytes(buffer * buf, const char * bytes, size_t len);
  • size_t get_length(buffer * buf);
  • void overwrite_autogrow(buffer * buf, size_t offset, const char * bytes, size_t len);
  • const char * to_string(buffer * buf);

Implementation should be clean and self-contained.

The overwrite_autogrow writes len of bytes to given offset while growing buffer as needed (as push_bytes does).

Ability to set allocator is optional, but preferable to have.

Does somebody know anything close to what I want?

Or, at least, any implementations worth looking at while implementing my own?

like image 231
Alexander Gladysh Avatar asked Dec 20 '25 04:12

Alexander Gladysh


1 Answers

VPOOL (BSD License)

http://www.bsdua.org/libbsdua.html#vpool

Vpool is an auto-resizeable buffer (dynamic array). Using it, you don't need to care about memory allocation, boundary checking, pointer manipulations and etc.

like image 188
f3lix Avatar answered Dec 22 '25 19:12

f3lix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!