{"id":32153048,"url":"https://github.com/acesuit/withalloc.jl","last_synced_at":"2026-02-21T03:02:33.530Z","repository":{"id":242122968,"uuid":"808337374","full_name":"ACEsuit/WithAlloc.jl","owner":"ACEsuit","description":"A simple Bumper convenience extension","archived":false,"fork":false,"pushed_at":"2025-11-26T02:48:28.000Z","size":56,"stargazers_count":8,"open_issues_count":3,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-11-29T05:36:17.906Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Julia","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/ACEsuit.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":"2024-05-30T21:26:56.000Z","updated_at":"2025-11-26T02:48:25.000Z","dependencies_parsed_at":"2024-06-17T22:45:43.972Z","dependency_job_id":"aa04026c-c731-45fa-81b3-ef7bfde48f20","html_url":"https://github.com/ACEsuit/WithAlloc.jl","commit_stats":null,"previous_names":["acesuit/withalloc.jl"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ACEsuit/WithAlloc.jl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ACEsuit%2FWithAlloc.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ACEsuit%2FWithAlloc.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ACEsuit%2FWithAlloc.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ACEsuit%2FWithAlloc.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ACEsuit","download_url":"https://codeload.github.com/ACEsuit/WithAlloc.jl/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ACEsuit%2FWithAlloc.jl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29672263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T00:11:43.526Z","status":"online","status_checked_at":"2026-02-21T02:00:07.432Z","response_time":107,"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-10-21T11:02:28.425Z","updated_at":"2026-02-21T03:02:33.524Z","avatar_url":"https://github.com/ACEsuit.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WithAlloc\n\n\u003c!-- [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://ACEsuit.github.io/WithAlloc.jl/stable/)\n[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://ACEsuit.github.io/WithAlloc.jl/dev/) --\u003e\n[![Build Status](https://github.com/ACEsuit/WithAlloc.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/ACEsuit/WithAlloc.jl/actions/workflows/CI.yml?query=branch%3Amain)\n\nThis package implements a very small extension to [Bumper.jl](https://github.com/MasonProtter/Bumper.jl). Bumper strongly enourages (almost enforces) that it is used purely from within `@no_escape` blocks. Bumper-allocating an array in a function and passing it back to the caller should generally be avoided. This results in a common pattern: \n```julia\n@no_escape begin \n   # determine the type and size a required array\n   T, N = determine_array(x1, x2, x3)\n   # preallocate some arrays\n   A = @alloc(T, N)\n   # do a computation on A \n   calculate_something!(A, x1, x2, x3)\nend \n```\nThe goal of `WithAlloc.jl` is to replace the above 3 lines with \n```julia \n@no_escape begin \n   A = @withalloc calculate_something!(x1, x2, x3)\nend\n```\n\n### Preliminary Documentation\n\nFor now, there are just a few simple use-case examples. Proper documentation will follow once the packages has been tested a bit and there is some agreement it will be long-term useful. \n```julia\nusing WithAlloc, LinearAlgebra, Bumper \n\n# simple allocating operation\nB = randn(5,10)\nC = randn(10, 3)\nA1 = B * C\n\n# we wrap mul! into a new function so we don't become pirates...\nmymul!(A, B, C) = mul!(A, B, C)\n\n# tell `WithAlloc` how to allocate memory for `mymul!`\nWithAlloc.whatalloc(::typeof(mymul!), B, C) = \n          (promote_type(eltype(B), eltype(C)), size(B, 1), size(C, 2))\n\n# the \"naive use\" of automated pre-allocation could look like this: \n# This is essentially the code that the macro @withalloc generates\n@no_escape begin \n   A2_alloc_info = WithAlloc.whatalloc(mymul!, B, C)\n   A2 = @alloc(A2_alloc_info...)\n   mymul!(A2, B, C)\n\n   @show A2 ≈ A1\nend\n\n# but the same pattern will be repreated over and over so ... \n@no_escape begin \n   A3 = @withalloc mymul!(B, C)\n   @show A3 ≈ A1 \nend\n\n# ------------------------------------------------------------------------\n\n# Multiple arrays is handled via tuples: \n\nB = randn(5,10)\nC = randn(10, 3)\nD = randn(10, 5)\nA1 = B * C \nA2 = B * D\n\nmymul2!(A1, A2, B, C, D) = mul!(A1, B, C), mul!(A2, B, D)\n\nfunction WithAlloc.whatalloc(::typeof(mymul2!), B, C, D) \n   T1 = promote_type(eltype(B), eltype(C)) \n   T2 = promote_type(eltype(B), eltype(D))\n   return ( (T1, size(B, 1), size(C, 2)), \n            (T2, size(B, 1), size(D, 2)) )\nend\n\n@no_escape begin \n   A1b, A2b = WithAlloc.@withalloc mymul2!(B, C, D)\n   @show A1 ≈ A1b, A2 ≈ A2b   # true, true \nend\n``` \n\nThis approach should become non-allocating, which we can quickly check. \n```julia\nusing WithAlloc, LinearAlgebra, Bumper \n\nmymul!(A, B, C) = mul!(A, B, C)\n\nWithAlloc.whatalloc(::typeof(mymul!), B, C) = \n          (promote_type(eltype(B), eltype(C)), size(B, 1), size(C, 2))\n\nnalloc = let B = randn(5,10), C = randn(10, 3)\n   @allocated sum( @withalloc mymul!(B, C) )\nend          \n\n@show nalloc  # 0 \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facesuit%2Fwithalloc.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facesuit%2Fwithalloc.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facesuit%2Fwithalloc.jl/lists"}