{"id":23888440,"url":"https://github.com/usmanmehmood55/ring_buffer","last_synced_at":"2026-06-11T23:31:09.415Z","repository":{"id":279000613,"uuid":"687339861","full_name":"usmanmehmood55/ring_buffer","owner":"usmanmehmood55","description":"A ring buffer implementation in C","archived":false,"fork":false,"pushed_at":"2023-09-05T07:22:40.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T04:41:43.905Z","etag":null,"topics":["buffer","c","data-structures","ring-buffer"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/usmanmehmood55.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-05T06:50:11.000Z","updated_at":"2023-09-05T13:46:39.000Z","dependencies_parsed_at":"2025-02-23T04:41:45.156Z","dependency_job_id":"363ed119-ccc9-4880-9f82-4a480aa52878","html_url":"https://github.com/usmanmehmood55/ring_buffer","commit_stats":null,"previous_names":["usmanmehmood55/ring_buffer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/usmanmehmood55/ring_buffer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fring_buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fring_buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fring_buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fring_buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usmanmehmood55","download_url":"https://codeload.github.com/usmanmehmood55/ring_buffer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fring_buffer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34222709,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","c","data-structures","ring-buffer"],"created_at":"2025-01-04T09:00:25.124Z","updated_at":"2026-06-11T23:31:09.180Z","avatar_url":"https://github.com/usmanmehmood55.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ring Buffer\n\nA ring buffer, also known as a circular buffer or cyclic buffer, is a data \nstructure that is used to store a fixed amount of data in a contiguous memory \nspace. The key characteristic of a ring buffer is that it is implemented as a \ncircular array, where the end of the buffer wraps around to the beginning of \nthe buffer, forming a closed loop.\n\n[![Build and Test](https://github.com/usmanmehmood55/ring_buffer/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/usmanmehmood55/ring_buffer/actions/workflows/build_and_test.yml)\n[![codecov](https://codecov.io/github/usmanmehmood55/ring_buffer/graph/badge.svg?token=CZTTM7JXRB)](https://codecov.io/github/usmanmehmood55/ring_buffer) \n\n## Uses and Benefits\n\nRing buffers are commonly used in embedded systems, real-time applications, \nand data acquisition systems where data needs to be continuously stored and \nprocessed. They are also used in audio and video processing, where a \nfixed-size buffer is used to store samples or frames for processing.\n\nThe ring buffer is an efficient data structure for storing data because it \nallows for constant time insertion and removal of elements. Since the buffer \nhas a fixed size, the insertion and removal of elements can be done using \npointer manipulation rather than copying data. This makes it ideal for \nhigh-speed data acquisition and processing, where the data is constantly being \nupdated.\n\nOne of the main benefits of using a ring buffer is that it provides a simple \nway to implement a first-in, first-out (FIFO) data structure. As new data is \nadded to the buffer, the oldest data is automatically removed, ensuring that \nthe buffer always contains the most recent data.\n\nAnother benefit of using a ring buffer is that it is very memory efficient. \nSince the buffer has a fixed size, the memory allocation can be done once and \nreused repeatedly. This is especially useful in embedded systems where memory \nis limited.\n\n\n## Setup\n\nFollowing tools are required to compile\n- [CMake](https://cmake.org/)\n- [Ninja](https://ninja-build.org/)\n- [GCC](https://gcc.gnu.org/)\n\nIn the repository directory, use CMake and Ninja to build\n```bash\ncmake -GNinja -Bbuild\nninja -C build\n```\n\nTo make a `Debug` build with coverage data,\n```bash\ncmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Debug\nninja -C build\n```\n\nTo run the test application\n```bash\n./build/ring_buffer.exe\n```\n\n## Files\n```\nring_buffer\n  |\n  |- ring_buffer.h\n  |- ring_buffer.c\n  |- test_ring_buffer.c\n  |- CMakeLists.txt \n```\n- The library consists of [`ring_buffer.h`](ring_buffer.h) and \n  [`ring_buffer.c`](ring_buffer.c) files.\n- The test and example code for using the library is provided in \n  [`test_ring_buffer.c`](test_ring_buffer.c)\n\n## Notes\n\nIn the current implementation, To prevent any external code from being able to write to properties of the buffer like `size` and `head`, the structure for the buffer has been made available only to the source file \n[`ring_buffer.c`](ring_buffer.c).\n```c\nstruct ring_buffer_t\n{\n    double   *buffer;    // pointer to the buffer\n    uint16_t size;       // maximum size of the buffer\n    uint16_t head;       // index of the current head element in the buffer\n    double   sum;        // sum of all the elements in the buffer.\n    uint16_t occupancy;  // number of elements currently in the buffer\n};\n```\n\nThe external code can use it's opaque type defined in the header file and this way it can only use the provided API to get any information it wants.\n```c\ntypedef struct ring_buffer_t ring_buffer_t;\n```\n\nThis however can be very counterintuitive because external code should be able\nto read the data from this structure without having to resort to an API. But \nsuch is the nature of C language, I guess.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusmanmehmood55%2Fring_buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusmanmehmood55%2Fring_buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusmanmehmood55%2Fring_buffer/lists"}