{"id":22642342,"url":"https://github.com/jan-moravec/circular-buffer","last_synced_at":"2025-10-07T05:12:40.399Z","repository":{"id":246658558,"uuid":"189881271","full_name":"jan-moravec/circular-buffer","owner":"jan-moravec","description":"C++ Template Class Container for shared data with model One Producer Multiple Consumers for multithreaded usage.","archived":false,"fork":false,"pushed_at":"2019-10-15T12:23:00.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-29T05:42:18.563Z","etag":null,"topics":["cpp"],"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/jan-moravec.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":"2019-06-02T18:30:57.000Z","updated_at":"2019-10-20T08:46:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"f1254b34-ea15-4c81-a45f-c8426b4dde5f","html_url":"https://github.com/jan-moravec/circular-buffer","commit_stats":null,"previous_names":["jan-moravec/circular-buffer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jan-moravec/circular-buffer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jan-moravec%2Fcircular-buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jan-moravec%2Fcircular-buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jan-moravec%2Fcircular-buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jan-moravec%2Fcircular-buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jan-moravec","download_url":"https://codeload.github.com/jan-moravec/circular-buffer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jan-moravec%2Fcircular-buffer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278722757,"owners_count":26034463,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"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":["cpp"],"created_at":"2024-12-09T05:06:28.382Z","updated_at":"2025-10-07T05:12:40.388Z","avatar_url":"https://github.com/jan-moravec.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Circular Buffer\n\nThe goal is to create a Template Class Container for multithreaded shared data with model One Producer Multiple Consumers.\n\nI need to work with frames from the camera in an embedded device, where performance is the main issue. The data are created in one thread and must be accessible from multiple threads with minimum copying. \nSo I created these classes for representing the camera data and for accessing the data itself safely.\n\nAssignment:\n- Have N frames or measurements (or any piece of data).\n- Access the data from multiple threads.\n- Generate the data in one thread.\n- The data itself must be shared memory due to performance.\n\n## Getting Started\n\nThe project has main.cpp and a curcularbuffer.h container header. The main.cpp contains unit testing.\n\nI used CMake for compilation, but it can be compiled with command:\n```\ng++ main.cpp -pthread -I./\n```\n\n### Prerequisites\n\nI am using C++17, so newer toolchain is needed.\n\n## Internals Description\n\nThe items of buffer are stored as pointer in a vector. There is a pointer to the current frame and final frame. \n- Current frame: next is always Final.\n- Final frame: last is always Current.\n\nThe frames thus are represented as a circular buffer. Each frame itself also has a pointer to next and precious. Each frame can be taken (semaphore is not a zero), or invalid (it is being updated).\n\nThe functions:\n```\nCircularItem *getNewCurrent();\nvoid setNewReady(CircularItem *item);\n```\nare used for getting an unused and valid frame, that will be updated (populate with new data), and then set as ready.\n\nSince none or all frames can be taken or invalid, the user must check if the frame is not a nullptr.\n\nIf some frames are taken, they will not be updated until they are available. That means that they will be skipped in the getNewCurrent() function. \n\n## Recommendation\n\nI tried to test all the function to guarantee it to be thread-safe. But for the best performance, you should always create enough frames in the buffer. If you know your application will take 32 frames at a time, make the buffer like 64 frames wide. \n\nOnce all frames are taken, it can not save any new data.\n\n## Author\n\n* **Jan Moravec**\n\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjan-moravec%2Fcircular-buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjan-moravec%2Fcircular-buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjan-moravec%2Fcircular-buffer/lists"}