A good C equivalent of STL vector?

后端 未结 7 1922
悲&欢浪女
悲&欢浪女 2021-02-02 12:54

I\'ve noticed that at several places in our code base we use dynamically expanding arrays, i.e. a base array coupled with an element counter and a \"max elements\" value.

7条回答
  •  遇见更好的自我
    2021-02-02 13:18

    I usually roll my own code for purposes such as this, like you did. It's not particularly difficult, but having type safety etc. is not easily achievable without a whole OO framework.

    As mentioned before, glib offers what you need - if glib2 is too big for you, you could still go with glib1.2. It's quite old, but doesn't have external dependencies (except for pthread if you need thread support). The code can also be integrated into larger projects, if necessary. It's LGPL licensed.

提交回复
热议问题