{"id":22796609,"url":"https://github.com/macmade/cpp-arc","last_synced_at":"2025-04-19T13:15:14.979Z","repository":{"id":3411923,"uuid":"4462496","full_name":"macmade/CPP-ARC","owner":"macmade","description":"C++ Automatic Reference Counting - This project intends to simplify memory management in C++, using reference counting.","archived":false,"fork":false,"pushed_at":"2021-08-02T23:01:15.000Z","size":48,"stargazers_count":27,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T08:11:25.105Z","etag":null,"topics":["arc","automatic","c-plus-plus","counting","reference","reference-count","reference-counting"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":false,"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/macmade.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}},"created_at":"2012-05-27T14:56:00.000Z","updated_at":"2023-11-12T16:57:00.000Z","dependencies_parsed_at":"2022-09-01T01:00:29.855Z","dependency_job_id":null,"html_url":"https://github.com/macmade/CPP-ARC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macmade%2FCPP-ARC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macmade%2FCPP-ARC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macmade%2FCPP-ARC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macmade%2FCPP-ARC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/macmade","download_url":"https://codeload.github.com/macmade/CPP-ARC/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249702006,"owners_count":21312759,"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":["arc","automatic","c-plus-plus","counting","reference","reference-count","reference-counting"],"created_at":"2024-12-12T05:13:44.578Z","updated_at":"2025-04-19T13:15:14.953Z","avatar_url":"https://github.com/macmade.png","language":"C","readme":"CPP-ARC\n=======\n\n[![Build Status](https://img.shields.io/travis/macmade/CPP-ARC.svg?branch=master\u0026style=flat)](https://travis-ci.org/macmade/CPP-ARC)\n[![Issues](http://img.shields.io/github/issues/macmade/CPP-ARC.svg?style=flat)](https://github.com/macmade/CPP-ARC/issues)\n![Status](https://img.shields.io/badge/status-inactive-lightgray.svg?style=flat)\n![License](https://img.shields.io/badge/license-boost-brightgreen.svg?style=flat)\n[![Contact](https://img.shields.io/badge/contact-@macmade-blue.svg?style=flat)](https://twitter.com/macmade)  \n[![Donate-Patreon](https://img.shields.io/badge/donate-patreon-yellow.svg?style=flat)](https://patreon.com/macmade)\n[![Donate-Gratipay](https://img.shields.io/badge/donate-gratipay-yellow.svg?style=flat)](https://www.gratipay.com/macmade)\n[![Donate-Paypal](https://img.shields.io/badge/donate-paypal-yellow.svg?style=flat)](https://paypal.me/xslabs)\n\nAbout\n-----\n\n**C++ Automatic Reference Counting**  \nThis project intends to simplify memory management in C++, using reference counting.  \nWhen allocating memory with the `new` operator, CPP-ARC automatically adds a few bytes of memory to manage a **retain count** on the memory area.\n\nMemory can then be **retained** or **released**.  \nAn allocation sets the retain count to 1. A retain increments it, and a release decrements it.  \nWhen the retain count reaches 0, the memory is freed.\n\nC++ classes are fully compatible with this scheme, as the destructors are called when the memory is freed.\n\nThis project also includes a template used to auto-release allocated memory, when it's not used anymore.\n\nDocumentation\n-------------\n\n### How-to: Retain / Release\n\nMemory allocated with `new` (primitive types or classes) can be retained or released.  \nTo do so, simply call:\n\n    template\u003c typename T \u003e T * CPPARC::retain( T * p );\n    template\u003c typename T \u003e void CPPARC::release( T * p );\n\nSo for instance:\n\n    class Point\n    {\n    \tpublic:\n    \t\t\n\t\t\tint x;\n\t\t\tint y;\n    };\n    \n\tint main( void )\n\t{\n\t\tPoint * p = new Point();\n\t\tchar  * s = new char[ 10 ];\n\t\t\n\t\tCPPARC::retain( p );\n\t\tCPPARC::release( p );\n\t\t\n\t\t// s will be freed here\n\t\tCPPARC::release( s );\n\t\t\n\t\t// p will be freed here - destructor will be called\n\t\tCPPARC::release( p );\n\t\t\n\t\treturn 0;\n\t}\n\n### How-to: Auto-released pointers\n\nAllocated memory can also be auto-released, when it's not used anymore.  \nIn order to to this, you can use the `CPPARC::AutoPointer` template class:\n\n    class Point\n    {\n    \tpublic:\n    \t\t\n\t\t\tint x;\n\t\t\tint y;\n    };\n\n\tint main( void )\n\t{\n\t\tCPPARC::AutoPointer\u003c Point \u003e p = new Point();\n\t\t\n\t\t// Nothing to do here, as the Point object will be automatically freed.\n\t\t\n\t\treturn 0;\n\t}\n\t\nThe `AutoPointer` template also provides direct access to class members:\n\n    class Foo\n    {\n    \tpublic:\n    \t\t\n\t\t\tvoid test( void )\n\t\t\t{\n\t\t\t\tstd::cout \u003c\u003c \"hello, world\" \u003c\u003c std::endl;\n\t\t\t}\n    };\n\n\tint main( void )\n\t{\n\t\tCPPARC::AutoPointer\u003c Foo \u003e f = new Foo();\n\t\t\n\t\t// Will output \"hello, world\", just as a normal pointer\n\t\tf-\u003etest();\n\t\t\n\t\treturn 0;\n\t}\n\t\nYou can of course use the `AutoPointer` template for functions/methods with arguments, or as return type:\n\n    class Point\n    {\n    \tpublic:\n    \t\t\n\t\t\tint x;\n\t\t\tint y;\n    };\n    \n\tCPPARC::AutoPointer\u003c Point \u003e getPoint( void )\n\t{\n\t\treturn new Point();\n\t}\n\t\n\tint main( void )\n\t{\n\t\tCPPARC::AutoPointer\u003c Point \u003e p = getPoint();\n\t\t\n\t\t// Nothing to do here, memory will be freed automatically.\n\t\t\n\t\treturn 0;\n\t}\n\nLicense\n-------\n\nCPP-ARC is released under the terms of the Boost Software License - Version 1.0.\n\nRepository Infos\n----------------\n\n    Owner:\t\t\tJean-David Gadina - XS-Labs\n    Web:\t\t\twww.xs-labs.com\n    Blog:\t\t\twww.noxeos.com\n    Twitter:\t\t@macmade\n    GitHub:\t\t\tgithub.com/macmade\n    LinkedIn:\t\tch.linkedin.com/in/macmade/\n    StackOverflow:\tstackoverflow.com/users/182676/macmade\n","funding_links":["https://patreon.com/macmade","https://paypal.me/xslabs"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacmade%2Fcpp-arc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmacmade%2Fcpp-arc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacmade%2Fcpp-arc/lists"}