{"id":28320827,"url":"https://github.com/cometscome/preallocatedarrays.jl","last_synced_at":"2026-02-24T04:01:28.707Z","repository":{"id":285710839,"uuid":"959065019","full_name":"cometscome/PreallocatedArrays.jl","owner":"cometscome","description":"Julia package for preallocated arrays","archived":false,"fork":false,"pushed_at":"2025-08-18T05:52:17.000Z","size":37,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-24T07:36:01.085Z","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/cometscome.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,"zenodo":null}},"created_at":"2025-04-02T08:00:26.000Z","updated_at":"2025-04-07T00:32:59.000Z","dependencies_parsed_at":"2025-06-23T13:42:45.048Z","dependency_job_id":"d951f059-8b49-4687-9a50-0ff564febe44","html_url":"https://github.com/cometscome/PreallocatedArrays.jl","commit_stats":null,"previous_names":["cometscome/temporalarrays.jl","cometscome/allocatedarrays.jl"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cometscome/PreallocatedArrays.jl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cometscome%2FPreallocatedArrays.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cometscome%2FPreallocatedArrays.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cometscome%2FPreallocatedArrays.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cometscome%2FPreallocatedArrays.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cometscome","download_url":"https://codeload.github.com/cometscome/PreallocatedArrays.jl/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cometscome%2FPreallocatedArrays.jl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29771038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-24T04:01:02.180Z","status":"ssl_error","status_checked_at":"2026-02-24T03:59:49.901Z","response_time":75,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-05-25T11:13:21.984Z","updated_at":"2026-02-24T04:01:28.689Z","avatar_url":"https://github.com/cometscome.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# PreallocatedArrays.jl\n\n[![Build Status](https://github.com/cometscome/PreallocatedArrays.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/cometscome/PreallocatedArrays.jl/actions/workflows/CI.yml?query=branch%3Amain)\n\n\n**PreallocatedArrays.jl** is a Julia package that provides a convenient way to manage and reuse allocated blocks of array data. It is particularly useful when you need to allocate many arrays of the same shape or size, and want to reduce overhead by reusing existing allocations.\n\n\n\n## Installation\n\n```julia\n] add PreallocatedArrays\n```\n\n## Main Features\n\n-\t**PreallocatedArray** type to store preallocated blocks.\n\n-\t**On-demand expansion** of the number of blocks if you request an index larger than the current capacity (up to a user-defined Nmax).\n\n-\t**Optional label system** to identify and retrieve blocks by label.\n\n-\tFunctions to handle usage flags, track which blocks are currently “in use,” and mark them as unused.\n\n## Usage\n\nBelow are some basic usage examples. For a more extensive reference, refer to the [tests](https://github.com/cometscome/PreallocatedArrays.jl/blob/main/test/runtests.jl).\n\n### Basic Allocation \u0026 Retrieval\n\n```julia\nusing PreallocatedArrays\n\n# Create a 3×3 random matrix\na = rand(3, 3)\n\n# Create an PreallocatedArray with 4 preallocated blocks of the same size\nblockvec = PreallocatedArray(a; num=4, haslabel=false)\n\n# Request one block from the pool\ndata_block, index = get_block(blockvec)\n\n# Use the block\ndata_block .= 1.0  # fill with ones\n\n# Mark the block as unused when you're done\nunused!(blockvec, index)\n```\n\n### Labels\n\n```julia\nusing PreallocatedArrays\n\n# Create a 10-element random vector\na = rand(10)\n\n# Create an PreallocatedArray with 4 labeled blocks\nblockvec2 = PreallocatedArray(a; num=4, haslabel=true)\n\n# Request a block by label\nblock, idx = new_block_withlabel(blockvec2, \"cat\")\nblock .= 100.0\n\n# Later, you can retrieve that same block by its label\nsame_block, same_idx = load_block_withlabel(blockvec2, \"cat\")\n@assert block === same_block  # They are the same array reference\n```\n\n## Creating from Vectors of Arrays\n\n```julia\nusing PreallocatedArrays\n\n# Suppose you have a vector of 10 Float64 vectors\ndata = [rand(4) for i in 1:10]\n\n# Create an PreallocatedArray from an existing vector of arrays\nblockvec = PreallocatedArray(data)\n\n# Also supports labeling\nlabels = [\"$(i)-th\" for i in 1:10]\nblockvec_labeled = PreallocatedArray(data, labels)\n\n# Display usage information\ndisplay(blockvec_labeled)\n```\n\n## Custum type\nYou can use a custum type. \nFor example, if you want to treat the gaugefields in Gaugefields.jl, \n```julia\nusing Gaugefields\nU =  Initialize_Gaugefields(3,0,4,4,4,4)\na = PreallocatedArray(U,num=10)\nU1,it = get_block(a)\n```\nTo use a custom type, ```Base.similar``` should be defined for the custom type. \n\n## Important Functions\n\n### 1. ```PreallocatedArray```\n\nConstructor function to create an ```PreallocatedArray``` with optional arguments for:\n-\t```num::Int``` – initial number of preallocated blocks\n-\t```haslabel::Bool``` – whether to enable label storage\n-\t```labeltype``` – the type of labels to store (by default ```String```, can be ```Symbol```, etc.)\n-\t```Nmax::Int``` – maximum capacity for the allocated array\n-\t```reusemode::Bool``` – if true, allows reusing a block without raising an error.\n\n\n### 2. ```get_block(preallocated_array)```\n\nFetches one unused block and returns ```(block, index)```. If there are no unused blocks, it expands the array up to Nmax.\n\n### 3. ```get_block(preallocated_array, num::Int)```\n\nFetches num unused blocks and returns ```(blocks, indices)```, where blocks is a vector of blocks, and indices is a vector of the corresponding indices.\n\n### 4. ```new_block_withlabel(preallocated_array, label)```\n\nFetches one unused block and *assigns* the label provided. Returns ```(block, index)```. If the label already exists, it raises an error.\n\n### 5. ```load_block_withlabel(preallocated_array, label)```\n\nReturns the block previously assigned to ```label```. Raises an error if the label was not set.\n\n### 6. ```unused!(preallocated_array, index)```\n\nMarks a block at a given index as no longer in use. There are also methods to mark multiple indices or *all* blocks as unused.\n\n\n### 7. ```set_reusemode!(preallocated_array, reusemode)```\n\nEnables or disables reusing a block. If ```reusemode``` is disabled, trying to get a block at an index already in use triggers an error.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcometscome%2Fpreallocatedarrays.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcometscome%2Fpreallocatedarrays.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcometscome%2Fpreallocatedarrays.jl/lists"}