{"id":25770578,"url":"https://github.com/stepainpy/alco","last_synced_at":"2026-06-12T19:33:02.568Z","repository":{"id":278816296,"uuid":"936538305","full_name":"Stepainpy/alco","owner":"Stepainpy","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-21T20:52:21.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T21:46:56.627Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Stepainpy.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":"2025-02-21T09:00:54.000Z","updated_at":"2025-02-21T20:52:25.000Z","dependencies_parsed_at":"2025-02-21T21:57:25.187Z","dependency_job_id":null,"html_url":"https://github.com/Stepainpy/alco","commit_stats":null,"previous_names":["stepainpy/alco"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Stepainpy/alco","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stepainpy%2Falco","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stepainpy%2Falco/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stepainpy%2Falco/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stepainpy%2Falco/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Stepainpy","download_url":"https://codeload.github.com/Stepainpy/alco/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stepainpy%2Falco/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34260309,"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-12T02:00:06.859Z","response_time":109,"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":[],"created_at":"2025-02-27T02:35:00.694Z","updated_at":"2026-06-12T19:33:02.546Z","avatar_url":"https://github.com/Stepainpy.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AlCo - Allocator collection\n\n## Overview\n\n\u003e **Disclaimer:**  \n\u003e The author is not liable for any malfunctions that may occur while using the provided allocators.\n\nAlCo - collection of simple memory allocation algorithms.  \nCommon API for allocators:\n- `init` - initialize new allocator object\n- `alloc` - return allocated memory\n- `free` - free memory by pointer\n- `free_all` - reset allocator and all getted memory\n\n## Table\n\n- [Arena](#arena)\n- [Stack](#stack)\n- [Pool](#pool)\n\n### Arena\n\nVariable-length allocation without random-order free.\n\nAllocation:\nReturn cuurent value of `head` and after add size of allocated memory. When free all arena, assing `head` value of `base`.\n\n#### Start state\n```\nbase/head                                           tail\nV                                                   V\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n|                    free memory                    |\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n```\n\n#### Allocate one `int`:\n``` c\nint* i = (int*)alco_arena_alloc(/* pointer to arena object */, sizeof *i);\n```\n```\nbase            head                                tail\nV               V                                   V\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n|       i       |            free memory            |\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n```\n\n#### Allocate three `short`:\n``` c\nshort* s3 = (short*)alco_arena_alloc(/* pointer to arena object */, sizeof *s3 * 3);\n```\n```\nbase                                    head        tail\nV                                       V           V\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n|       i       | s3[0]   s3[1]   s3[2] | free  mem |\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n```\n\n### Stack\n\nVariable-length allocation with LIFO allocation/free memory.\n\nAllocation:\nReturn current value of `head`, add `size` by `head` and paste return pointer equal pointer to allocated memory. When free, subtract size of size type from `head` and assing `head` equal return address.\n\n#### Stack frame:\n```\n|\u003c---------- frame_size ----------\u003e|\n|   allocated memory   |  ret ptr  |\n```\n\n`frame_size` = sizeof pointer + size of allocated block\n\n#### Start state:\n```\nbase/head                                           tail\nV                                                   V\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n|                    free memory                    |\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n```\nP.S.: for example use size of pointer equal 1\n\n#### Allocate one `int`:\n``` c\nint* i = (int*)alco_stack_alloc(/* pointer to stack object */, sizeof *i);\n```\n```\nbase                head                            tail\nV                   V                               V\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n|       i       | R |          free memory          |\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n^                 |\n'-----------------'\n```\n\n#### Allocate three `char`:\n``` c\nchar* chs = (char*)alco_stack_alloc(/* pointer to stack object */, sizeof *chs * 3);\n```\n```\nbase                                head            tail\nV                                   V               V\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n|       i       | R |    chs    | R |  free memory  |\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n^                 | ^             |\n'-----------------' '-------------'\n```\n\n#### Free `chs`:\n``` c\nalco_stack_free(/* pointer to stack object */);\n```\n```\nbase                            head \u003c\u003c\u003c            tail\nV                               V                   V\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n|       i       | R |    chs    | R |  free memory  |\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n^                 | ^             |\n'-----------------' '-------------'\n```\n```\nbase                head                            tail\nV                   V                               V\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n|       i       | R |          free memory          |\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n^                 |\n'-----------------'\n```\n\n### Pool\n\nFixed-size block allocation without guarantee contiguous memory. [Free list](https://en.wikipedia.org/wiki/Free_list) - data structure for store places of free blocks.\n\nAllocation:\nReturn current value of `head` and after assing value of field `next`. When free pointer, create a new 'header' structure with `next` equal current value of `head` and assing `head` value of getted pointer.  \nAs example use pool for `int` type.\n\n#### Chunk structure:\n```\n|\u003c---------- chunk_size ---------\u003e|\n|  ptr to next chunk  |  padding  |\n```\n\n`chunk_size` = max(sizeof pointer, sizeof type)\n\n#### Start state:\n```\nhead/chunks\n| .---------. .---------. .---------. .---\u003e NULL\nV |         V |         V |         V |\n+---+-------+---+-------+---+-------+---+-------+\n| n |  pad  | n |  pad  | n |  pad  | n |  pad  |\n+---+-------+---+-------+---+-------+---+-------+\n```\n\n#### Allocate one `int`:\n``` c\nint* a = (int*)alco_pool_alloc(/* pointer to pool object */);\n```\n```\nchunks      head\n|           | .---------. .---------. .---\u003e NULL\nV           V |         V |         V |\n+-----------+---+-------+---+-------+---+-------+\n| alloc mem | n |  pad  | n |  pad  | n |  pad  |\n+-----------+---+-------+---+-------+---+-------+\n```\n\n#### Allocate again:\n``` c\nint* b = (int*)alco_pool_alloc(/* pointer to pool object */);\n```\n```\nchunks                  head\n|                       | .---------. .---\u003e NULL\nV                       V |         V |\n+-----------------------+---+-------+---+-------+\n|   allocated  memory   | n |  pad  | n |  pad  |\n+-----------------------+---+-------+---+-------+\n```\n\n#### Free pointer `a`:\n``` c\nalco_pool_free(/* pointer to pool object */, a);\n```\n```\nchunks/a                head\n|                       | .---------. .---\u003e NULL\nV                       V |         V |\n+-----------------------+---+-------+---+-------+\n|   allocated  memory   | n |  pad  | n |  pad  |\n+-----------------------+---+-------+---+-------+\n```\n```\nchunks/head\n| .---------------------. .---------. .---\u003e NULL\nV |                     V |         V |\n+---+-------+-----------+---+-------+---+-------+\n| n |  pad  | alloc mem | n |  pad  | n |  pad  |\n+---+-------+-----------+---+-------+---+-------+\n```\n\n#### Free pointer `b`:\n``` c\nalco_pool_free(/* pointer to pool object */, b);\n```\n```\nchunks/head\n| .---------------------. .---------. .---\u003e NULL\nV |                     V |         V |\n+---+-------+-----------+---+-------+---+-------+\n| n |  pad  | alloc mem | n |  pad  | n |  pad  |\n+---+-------+-----------+---+-------+---+-------+\n            ^\n            |\n            b\n```\n```\nchunks\n| ,---------------------. ,---------. ,---\u003e NULL\nV |                     V |         V |\n+---+-------+---+-------+---+-------+---+-------+\n| n |  pad  | n |  pad  | n |  pad  | n |  pad  |\n+---+-------+---+-------+---+-------+---+-------+\n^           ^ |\n'-------------'\n            |\n            head\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepainpy%2Falco","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstepainpy%2Falco","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepainpy%2Falco/lists"}