{"id":15049279,"url":"https://github.com/mobius3/naughty-buffers","last_synced_at":"2026-01-29T03:04:16.229Z","repository":{"id":195281359,"uuid":"692479488","full_name":"mobius3/naughty-buffers","owner":"mobius3","description":"C library providing a buffer that can automatically grow","archived":false,"fork":false,"pushed_at":"2024-03-06T00:11:52.000Z","size":177,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-20T20:41:06.939Z","etag":null,"topics":["buffer","c99","dynamic-array","typesafe-array"],"latest_commit_sha":null,"homepage":"https://mobius3.github.io/naughty-buffers/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mobius3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-16T15:53:53.000Z","updated_at":"2024-02-27T13:11:34.000Z","dependencies_parsed_at":"2024-02-22T14:30:30.701Z","dependency_job_id":"59a3a406-4f31-4acd-8705-7b05fb44305c","html_url":"https://github.com/mobius3/naughty-buffers","commit_stats":null,"previous_names":["mobius3/naughty-buffers"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobius3%2Fnaughty-buffers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobius3%2Fnaughty-buffers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobius3%2Fnaughty-buffers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobius3%2Fnaughty-buffers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mobius3","download_url":"https://codeload.github.com/mobius3/naughty-buffers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243505960,"owners_count":20301619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["buffer","c99","dynamic-array","typesafe-array"],"created_at":"2024-09-24T21:19:26.532Z","updated_at":"2026-01-29T03:04:16.137Z","avatar_url":"https://github.com/mobius3.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Naughty Buffers 😈\n\nNaughty Buffers is a C99 library that provides generic, type-unsafe, _\"stretchy buffer\"_ that can hold any type of data\ninternally and allows you to access them later. It automatically grows when assigning, pushing or inserting new data\nblocks.\n\nIt also allows you to specify your own memory-management replacement functions for when you don't want to use standard\nones (`malloc` and friends)\n\n## Features\n\n- Buffer automatically grows to accommodate for data\n- Allows for custom memory functions set at runtime\n- Macros to generate type-safe* wrappers\n- No external dependencies\n- Clear, easy to use and fully documented API\n- Unit tested 😁\n- _Valgrind_: All heap blocks were freed -- no leaks are possible\n\nWrappers are not really type-safe at implementation level, but they allow you to use a type-safe API.\n\n## Examples\n\n**Non-advanced usage**\n\n```c\n#include \"naughty-buffers/buffer.h\"\n#include \u003cstdio.h\u003e\n\nint read_int(struct nb_buffer * buffer, size_t index) {\n  int * read_value = nb_at(\u0026buffer, index);\n  return *read_value;\n}\n\nint main(void) {\n    struct nb_buffer buffer;\n    nb_init(\u0026buffer, sizeof(int));\n    \n    int value = 10;\n    nb_push(\u0026buffer, \u0026value);\n    printf(\"%d\\n\", read_int(\u0026buffer, 0)); // prints 10\n    \n    value = 30;\n    nb_insert(\u0026buffer, 0, \u0026value);\n    printf(\"%d\\n\", read_int(\u0026buffer, 0)); // prints 30\n    \n    \n    value = 50;\n    nb_assign(\u0026buffer, 1, \u0026value);\n    printf(\"%d\\n\", read_int(\u0026buffer, 1)); // prints 50\n    printf(\"%d\\n\", read_int(\u0026buffer, 0)); // prints 30\n    \n    return 0;\n}\n```\n\n**With custom memory functions**\n\n```c\n#include \"naughty-buffers/buffer.h\"\n\nvoid * my_alloc(size_t memory_size, void * memory_context);\nvoid my_release(void * ptr, void * memory_context);\nvoid * my_realloc(void * ptr, size_t memory_size, void * memory_context);\nvoid * my_copy(void * destination, const void * source, size_t size, void * memory_context);\nvoid * my_move(void * destination, const void * source, size_t size, void * memory_context);\nvoid * memory_context;\n\n\nint main(void) {\n  struct nb_buffer buffer;\n  nb_init_advanced(\n      \u0026buffer,\n      sizeof(int),\n      my_alloc,\n      my_realloc,\n      my_release,\n      my_copy,\n      my_move,\n      memory_contex\n  );\n  \n  return 0;\n}\n```\n\nCheck [the tests folder](/src/tests) and [the examples folder](/src/examples) for more complex examples\n\n## Integrating with your code\n\n### Using pre-built releases\n\nDownload a pre-built release package suitable for your platform and\nuncompress it somewhere you'll remember later (usually where you put\nother development libraries). Let's assume you uncompressed naughty-buffers to\n`/home/me/libs/naughty-buffers`.\n\n**Using CMake**: If you're using CMake, specify the variable\n`CMAKE_PREFIX_PATH` to point to it before running CMake in your project:\n\n```shell script\ncmake -DCMAKE_PREFIX_PATH=/home/me/libs\n```\n\nThen you can use `find_package(naughty-buffers)` and\n`target_link_libraries(\u003cyour-executable\u003e PUBLIC naughty-buffers)` to link\n`\u003cyour-executable\u003e` against naughty-buffers.\n\n**Not using CMake**: Assuming you uncompressed naughty-buffers to the same path as\nabove, you should configure your build system to look for include files\ninside `/home/me/libs/naughty-buffers/include` and to look for shared objects to\nlink against inside `/home/me/libs/naughty-buffers/lib`. In case of Windows, you\nshould also point your linker to `naughty-buffers/bin` as well.\n\n### Using a source release and CMake\n\nUncompress naughty-buffers in a folder inside your project (e.g,\n`your-project/third-party/naughty-buffers`) and then use\n`add_subdirectory(third-party/naughty-buffers EXCLUDE_FROM_ALL)` to add the\nlibrary target. Then you can use `find_package(naughty-buffers)` and\n`target_link_libraries(\u003cyour-executable\u003e PUBLIC naughty-buffers)` to link\n`\u003cyour-executable\u003e` against naughty-buffers.\n\nCompiling the `.c` files directly in your project is not recommended nor\nsupported.\n\n## Compile from source\n\nYou'll need CMake installed and in your path and also capable of finding\nyou compiler and linker. Then, after checking out this repository:\n\n```shell script\nmkdir build/\ncd build/\ncmake ..\ncmake --build .\n```\n\n## Examples\n\nExamples for C are in the [src/examples](src/examples) folder. To build them, when running cmake as in [Compile from source](#compile-from-source), add the following variable:\n\n```shell script\ncmake .. -DBUILD_EXAMPLES=1\n```\n\n## Documentation\n\nSee [here](https://mobius3.github.io/naughty-buffers)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmobius3%2Fnaughty-buffers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmobius3%2Fnaughty-buffers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmobius3%2Fnaughty-buffers/lists"}