{"id":22957549,"url":"https://github.com/tca166/localcachinglib","last_synced_at":"2025-04-02T01:45:23.309Z","repository":{"id":109713979,"uuid":"600503699","full_name":"TCA166/localCachingLib","owner":"TCA166","description":"A C library for storing data on the hard drive instead of RAM","archived":false,"fork":false,"pushed_at":"2023-02-15T11:10:19.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-07T16:43:34.310Z","etag":null,"topics":["c","memory","memory-management"],"latest_commit_sha":null,"homepage":"","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/TCA166.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-02-11T17:40:26.000Z","updated_at":"2023-02-15T11:13:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"9841da1a-953b-4ff2-b916-a5ba4f296d4a","html_url":"https://github.com/TCA166/localCachingLib","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/TCA166%2FlocalCachingLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TCA166%2FlocalCachingLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TCA166%2FlocalCachingLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TCA166%2FlocalCachingLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TCA166","download_url":"https://codeload.github.com/TCA166/localCachingLib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246741191,"owners_count":20826063,"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":["c","memory","memory-management"],"created_at":"2024-12-14T17:17:47.575Z","updated_at":"2025-04-02T01:45:23.301Z","avatar_url":"https://github.com/TCA166.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# localCachingLib\n\nA library for storing variables in local binary files as opposed to RAM.\n\n## How to use it\n\n1. Create a cache struct  \n    Each cache struct has a filename associated with it (it's your responsibility to ensure that caches do not share names), and a size of one element.\n    This effectively means that each cache has an associated type like int. Ideally you name them to make it clear what type each cache is.\n    ```C\n    struct cache intArr = createCache(sizeof(int), \"cache.bin\");\n    ```\n2. Write something to the cache  \n    Variables can be written to the cache almost as if it is an array\n    ```C\n    int arr1[5] = {1, 2, 3, 4, 5};\n    int arr2[5] = {6, 7, 8, 9, 10};\n\n    writeToCache(arr1, \u0026intArr, 5);\n    writeToCache(arr2, \u0026intArr, 5);\n    ```\n    In this example the intArr cache holds now an array of 10 ints\n3. Read something from the cache  \n    Reading things from the cache is also rather easy.\n    ```C\n    printf(\"%d\", arr1[1]); //prints 2\n    printf(\"%d\", (int)(readFromCache(\u0026intArr, 1, 1))); //prints 2\n    ```\n4. Delete the cache  \n    When your program stops execution the struct will be of course automaticly lost. Hovewer the file will remain. So the same way it's good practice to free everything at the end of the program, it's also good practice to freeCache each cache you have created\n\n\n## Typeless vs Normal caches\n\nThis library has two very similar structs and associated functions. Normal caches and typeless caches. \nSo far the examples have only shown how to use the normal caches. That is because typeless caches are less reliable and there is a lot more that can go wrong.\nNormal caches are essentially files with a memory representation of an array. Since each element has a given size reading them is easy and painless.\nTypeless caches hovewer while allowing for variable element size, are forced to seperate each element with a delimiter, making reading them a lot more problematic and prone to errors.\nThe delmiter is by default a string \"\\0\\10\" and since it's a string there's a third hidden null character. This is a rather distinct combination that shouldn't overlap with most data.\n\n### Redefining the delimiter\n\nIn order to redefine the delimiter you have to redefine the following macros that are in the localCachingLib.h\n\n```C\n//the actual value of the delimiter\n#define typelessDelimiter \"\\0;\"\n//size in bytes of the delimiter\n#define delimiterSize 3 * sizeof(char)\n//A macro for checking if the provided pointer points to a delimiter \n#define isDelimit(a) (a[0] == typelessDelimiter[0] \u0026\u0026 a[1] == typelessDelimiter[1] \u0026\u0026 a[2] == typelessDelimiter[2])\n```\n\n## How to use typeless Caches\n\nThey function very similarly to normal caches, except you can't write multiple elements at a time to limit the amount of things that can go wrong.  \nHere's an example use case:\n\n```C\nstruct typelessCache typeless = createTypelessCache(\"typeless.bin\");\n\nwriteTypeless(\u0026typeless, arr1, sizeof(int));\n\nint* res = (int*)readTypeless(\u0026typeless, 0);\n\nprintf(\"\\n%d\", (int)*res);\n\nfree(res);\n\nwipeTypeless(\u0026typeless);\nfreeTypeless(\u0026typeless);\n```\n\n## License\n\n[![CCimg](https://i.creativecommons.org/l/by/4.0/88x31.png)](http://creativecommons.org/licenses/by/4.0/)  \nThis work is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftca166%2Flocalcachinglib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftca166%2Flocalcachinglib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftca166%2Flocalcachinglib/lists"}