{"id":24973392,"url":"https://github.com/humanwhocodes/memory","last_synced_at":"2025-04-11T08:44:03.666Z","repository":{"id":40491667,"uuid":"336444579","full_name":"humanwhocodes/memory","owner":"humanwhocodes","description":"A JavaScript implementation of dynamic memory.","archived":false,"fork":false,"pushed_at":"2023-12-15T02:47:55.000Z","size":64,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-25T20:02:59.271Z","etag":null,"topics":["javascript","memory","memory-allocation","memory-management"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/humanwhocodes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-02-06T03:12:58.000Z","updated_at":"2024-02-12T03:39:06.000Z","dependencies_parsed_at":"2025-02-03T18:59:19.577Z","dependency_job_id":"754b16dd-3056-4a72-a8ea-74f9f96fbbc9","html_url":"https://github.com/humanwhocodes/memory","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanwhocodes%2Fmemory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanwhocodes%2Fmemory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanwhocodes%2Fmemory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanwhocodes%2Fmemory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/humanwhocodes","download_url":"https://codeload.github.com/humanwhocodes/memory/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248362631,"owners_count":21091169,"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":["javascript","memory","memory-allocation","memory-management"],"created_at":"2025-02-03T18:59:10.236Z","updated_at":"2025-04-11T08:44:03.638Z","avatar_url":"https://github.com/humanwhocodes.png","language":"JavaScript","readme":"# Memory utility\n\nby [Nicholas C. Zakas](https://humanwhocodes.com)\n\nIf you find this useful, please consider supporting my work with a [donation](https://humanwhocodes.com/donate).\n\n## Description\n\nA JavaScript implementation of dynamic memory using an `ArrayBuffer` as the memory storage.\n\n**Warning:** Very experimental right now. May or may not be useful.\n\n## Usage\n\n### Node.js\n\nInstall using [npm][npm] or [yarn][yarn]:\n\n```\nnpm install @humanwhocodes/memory --save\n\n# or\n\nyarn add @humanwhocodes/memory\n```\n\nImport into your Node.js project:\n\n```js\n// CommonJS\nconst { Memory } = require(\"@humanwhocodes/memory\");\n\n// ESM\nimport { Memory } from \"@humanwhocodes/memory\";\n```\n\n### Deno\n\nImport into your Deno project:\n\n```js\nimport { Memory } from \"https://cdn.skypack.dev/@humanwhocodes/memory?dts\";\n```\n\n### Browser\n\nIt's recommended to import the minified version to save bandwidth:\n\n```js\nimport { Memory } from \"https://cdn.skypack.dev/@humanwhocodes/memory?min\";\n```\n\nHowever, you can also import the unminified version for debugging purposes:\n\n```js\nimport { Memory } from \"https://cdn.skypack.dev/@humanwhocodes/memory\";\n```\n\n## API\n\nAfter importing, create a new instance of `Memory` and pass in an `ArrayBuffer` to represent your memory:\n\n```js\nconst memory = new Memory(new ArrayBuffer(64));\n\n// allocate 4 bytes\nconst address = memory.allocate(4);\n\n// address is 0 if no memory could be allocated\nif (address) {\n\n    // write some data into that address - must be a typed array\n    memory.write(address, new Uint8Array([1, 2, 3, 4]));\n\n    // read the data back out - returns a Uint8Array\n    const data = memory.read(address);\n\n    // free up the mory\n    memory.free(address);\n\n} else {\n    console.error(\"Could not allocate memory.\");\n}\n```\n\n## Safety\n\nThe `Memory` class provides safeguards to ensure you aren't accidentally writing or reading data where you shouldn't:\n\n1. `allocate()` returns `0` when no more memory can be allocated, allowing you to handle out-of-memory issues gracefully.\n1. `write()` throws an error when:\n    1. You try to write to address `0`.\n    1. You try to write to an unallocated address.\n    1. The data you're writing is larger than the allocated space.\n1. `read()` throws an error if you attempt to read from an invalid address.\n1. `free()` throws an error if you attempt to free an invalid address.\n\nAll of this is to say, it should be difficult to accidentally overwrite memory locations.\n\n## Developer Setup\n\n1. Fork the repository\n2. Clone your fork\n3. Run `npm install` to setup dependencies\n4. Run `npm test` to run tests\n\n## License\n\nApache 2.0\n\n[npm]: https://npmjs.com/\n[yarn]: https://yarnpkg.com/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumanwhocodes%2Fmemory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhumanwhocodes%2Fmemory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumanwhocodes%2Fmemory/lists"}