{"id":26777242,"url":"https://github.com/timothymeadows/pinnedmemory","last_synced_at":"2026-03-07T21:32:26.699Z","repository":{"id":96219696,"uuid":"278908919","full_name":"TimothyMeadows/PinnedMemory","owner":"TimothyMeadows","description":"PinnedMemory is a cross platform method for creating, and accessing pinned, and locked memory in .NET Core.","archived":false,"fork":false,"pushed_at":"2024-10-14T22:00:18.000Z","size":28,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T04:49:13.867Z","etag":null,"topics":["linux","mac","memory","net","netcore","windows"],"latest_commit_sha":null,"homepage":"","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/TimothyMeadows.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":"2020-07-11T17:23:04.000Z","updated_at":"2024-10-14T21:54:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"faae3fdd-73b7-4fc1-ba1c-d7e7d58a69d6","html_url":"https://github.com/TimothyMeadows/PinnedMemory","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FPinnedMemory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FPinnedMemory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FPinnedMemory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FPinnedMemory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimothyMeadows","download_url":"https://codeload.github.com/TimothyMeadows/PinnedMemory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249192413,"owners_count":21227783,"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":["linux","mac","memory","net","netcore","windows"],"created_at":"2025-03-29T04:49:17.481Z","updated_at":"2026-03-07T21:32:26.596Z","avatar_url":"https://github.com/TimothyMeadows.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# PinnedMemory\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![nuget](https://img.shields.io/nuget/v/PinnedMemory.svg)](https://www.nuget.org/packages/PinnedMemory/)\n\n**PinnedMemory** is a cross-platform, high-performance solution for creating, accessing, and managing pinned and locked memory for Windows, macOS, and Linux operating systems in .NET Core. It provides automatic memory pinning and optional locking for sensitive operations, helping you prevent garbage collection relocations and offering enhanced performance in low-level memory manipulation scenarios.\n\n# Install\n\nFrom a command prompt:\n\n```bash\ndotnet add package PinnedMemory\n```\n\n```bash\nInstall-Package PinnedMemory\n```\n\nYou can also search for the package via your NuGet UI or website:\n\n[NuGet: PinnedMemory](https://www.nuget.org/packages/PinnedMemory/)\n\n# Features\n\n- Cross-platform memory management for Windows, Linux, and macOS.\n- Supports several primitive types (e.g., `byte`, `int`, `float`, etc.).\n- Offers zeroing, locking, and unlocking of memory for security and performance.\n- Prevents garbage collection from relocating memory by pinning the array in memory.\n- Efficient cloning and pooling of arrays using `ArrayPool\u003cT\u003e`.\n- Optimized for performance with aggressive inlining and reduced allocations.\n\n# Usage\n\n### Basic Example\n\n```csharp\nusing (var pin = new PinnedMemory\u003cbyte\u003e(new byte[3]))\n{\n    pin[0] = 65;\n    pin[1] = 61;\n    pin[2] = 77;\n}\n```\n\n### Writing to Memory\n\n```csharp\nusing (var pin = new PinnedMemory\u003cbyte\u003e(new byte[3]))\n{\n    pin.Write(0, 65);\n    pin.Write(1, 61);\n    pin.Write(2, 77);\n}\n```\n\n### Reading from Memory\n\n```csharp\nusing (var pin = new PinnedMemory\u003cbyte\u003e(new byte[] {65, 61, 77}, false))\n{\n    var byte1 = pin[0];\n    var byte2 = pin[1];\n    var byte3 = pin[2];\n}\n```\n\n```csharp\nusing (var pin = new PinnedMemory\u003cbyte\u003e(new byte[] {65, 61, 77}, false))\n{\n    var byte1 = pin.Read(0);\n    var byte2 = pin.Read(1);\n    var byte3 = pin.Read(2);\n}\n```\n\n### Cloning Pinned Memory\n\n```csharp\nusing (var pin = new PinnedMemory\u003cbyte\u003e(new byte[] {65, 61, 77}, false))\n{\n    var clone = pin.Clone();\n    var clonedArray = clone.ToArray();\n}\n```\n\n### Zeroing, Locking, and Unlocking Memory\n\n```csharp\nusing (var pin = new PinnedMemory\u003cbyte\u003e(new byte[3], zero: true, locked: true))\n{\n    // Memory is automatically zeroed and locked.\n    // Perform secure operations.\n}\n```\n\n### Supported Types\n\nThe following primitive types are supported in `PinnedMemory`:\n\n- `sbyte`\n- `byte`\n- `char`\n- `short`\n- `ushort`\n- `int`\n- `uint`\n- `long`\n- `ulong`\n- `float`\n- `double`\n- `decimal`\n- `bool`\n\n# API Reference\n\n### Constructor\n\n```csharp\nPinnedMemory(T[] value, bool zero = true, bool locked = true, SystemType type = SystemType.Unknown)\n```\n\n- **value**: The array to pin in memory.\n- **zero**: Optional. If `true`, the memory will be zeroed out after allocation.\n- **locked**: Optional. If `true`, the memory will be locked in RAM to prevent paging.\n- **type**: Optional. Specifies the OS platform (`SystemType.Windows`, `SystemType.Linux`, `SystemType.Osx`). If `Unknown`, it is detected automatically.\n\n### Properties\n\n- **T this[int i]**: Indexer for accessing elements in the pinned array.\n- **int Length**: Returns the length of the pinned array.\n\n### Methods\n\n- **T[] Read()**: Returns the entire pinned array.\n- **T Read(int index)**: Reads the value at the specified index.\n- **void Write(int index, T value)**: Writes the value at the specified index.\n- **PinnedMemory\u003cT\u003e Clone()**: Clones the pinned memory array and returns a new `PinnedMemory\u003cT\u003e` object.\n- **T[] ToArray()**: Returns a copy of the pinned memory as an array.\n- **void Dispose()**: Frees the pinned memory, zeroes it out, and unlocks it if locked.\n\n# License\n\nThis library is licensed under the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothymeadows%2Fpinnedmemory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimothymeadows%2Fpinnedmemory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimothymeadows%2Fpinnedmemory/lists"}