开发者

Growable buffer for plain C [closed]

开发者 https://www.devze.com 2022-12-20 07:10 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 7 years ago.

Improve this question

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 off开发者_JS百科set, 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?


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.


http://library.gnome.org/devel/glib/stable/glib-Arrays.html

not sure if it implements overwrite_autogrow though, as I don't know what you mean by this. You want to manually set a capacity? If so g_array_set_size.

However, the licence may be a problem, but you should be able to use it as LGPL. I don't know if that's comaptible with MIT or not.

0

精彩评论

暂无评论...
验证码 换一张
取 消