# cysharp/memorypack

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/cysharp-memorypack).**

4,598 stars · 305 forks · C# · MIT

## Links

- GitHub: https://github.com/Cysharp/MemoryPack
- awesome-repositories: https://awesome-repositories.com/repository/cysharp-memorypack.md

## Description

MemoryPack is a high-performance binary serialization library for C# and Unity. It provides a zero-allocation data pipeline and a schema-evolution framework designed to minimize memory allocations and encoding overhead.

The project utilizes compile-time source generators to avoid runtime reflection and implements a zero-encoding binary format for maximum throughput. It distinguishes itself through a zero-allocation approach that reuses object instances to reduce garbage collection pressure and copies the memory layout of unmanaged structs directly to binary streams.

The library covers binary schema versioning for backward compatibility and supports asynchronous collection streaming for large datasets. It includes a TypeScript type generator to synchronize data structures between C# and TypeScript for cross-language data exchange. Additional capabilities include payload compression, custom formatter implementations, and serialization callbacks.

## Tags

### Data & Databases

- [High-Performance Binary Serialization](https://awesome-repositories.com/f/data-databases/high-performance-binary-serialization.md) — Provides an optimized binary serialization engine for C# designed for minimal CPU and memory overhead.
- [Direct-Memory Struct Copying](https://awesome-repositories.com/f/data-databases/data-engineering-infrastructure/data-persistence-storage/data-storage-architectures/zero-copy-memory-mappings/direct-memory-struct-copying.md) — Implements high-speed serialization by copying the memory layout of blittable structs directly to the output stream.
- [Schema Versioning](https://awesome-repositories.com/f/data-databases/data-schema-management/schema-versioning.md) — Ensures backward compatibility by tracking member additions and handling schema mismatches between data versions.
- [Schema Evolution](https://awesome-repositories.com/f/data-databases/data-type-schemas/schema-evolution.md) — Supports adding new members to serialized objects while maintaining compatibility with older data versions. ([source](https://cdn.jsdelivr.net/gh/cysharp/memorypack@main/README.md))
- [Custom Serializer Implementations](https://awesome-repositories.com/f/data-databases/data-type-managers/dynamic-type-managers/custom-type-serializers/custom-serialization-interfaces/custom-serializer-implementations.md) — Allows the definition of manual serialization logic for external types by implementing custom formatter classes. ([source](https://cdn.jsdelivr.net/gh/cysharp/memorypack@main/README.md))
- [TypeScript Type Generators](https://awesome-repositories.com/f/data-databases/schema-generators/typescript-type-generators.md) — Generates TypeScript interfaces from C# type definitions to maintain consistent data models.
- [C# to TypeScript Generators](https://awesome-repositories.com/f/data-databases/schema-generators/typescript-type-generators/c-to-typescript-generators.md) — Provides a utility to convert C# types into TypeScript interfaces for consistent cross-language data exchange. ([source](https://cdn.jsdelivr.net/gh/cysharp/memorypack@main/README.md))

### DevOps & Infrastructure

- [Binary Serialization Versioning](https://awesome-repositories.com/f/devops-infrastructure/version-upgrades/artifact-versioning/binary-serialization-versioning.md) — Ensures that new software versions can read older binary data through robust schema versioning.

### Operating Systems & Systems Programming

- [Blittable Struct Serializations](https://awesome-repositories.com/f/operating-systems-systems-programming/blittable-struct-serializations.md) — Writes the memory layout of unmanaged structs directly to binary streams for maximum processing speed. ([source](https://cdn.jsdelivr.net/gh/cysharp/memorypack@main/README.md))
- [Memory Optimization Techniques](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/process-and-memory-management/memory-management/allocation-strategies/dynamic-memory-allocation/stack-allocation-optimizations/memory-optimization-techniques.md) — Reduces GC pressure through object reuse and direct raw struct serialization in C#.
- [Zero-Allocation Binary IO](https://awesome-repositories.com/f/operating-systems-systems-programming/zero-allocation-binary-io.md) — Implements a memory-efficient binary IO pipeline that minimizes allocations during serialization and deserialization.

### Programming Languages & Runtimes

- [Serialization Code Generators](https://awesome-repositories.com/f/programming-languages-runtimes/ahead-of-time-compilation/serialization-code-generators.md) — Utilizes compile-time source generators to create static serialization logic and eliminate runtime reflection overhead.
- [Object Serialization](https://awesome-repositories.com/f/programming-languages-runtimes/object-serialization.md) — Provides high-performance conversion of plain C# objects into a binary format and back. ([source](https://cdn.jsdelivr.net/gh/cysharp/memorypack@main/README.md))
- [Cross-Language Data Exchange](https://awesome-repositories.com/f/programming-languages-runtimes/cross-language-data-exchange.md) — Synchronizes data structures between C# and TypeScript to ensure type-safe API communication.

### Software Engineering & Architecture

- [Object Instance Reuses](https://awesome-repositories.com/f/software-engineering-architecture/object-instance-reuses.md) — Provides the ability to deserialize data into existing object instances to minimize memory allocations and GC frequency. ([source](https://cdn.jsdelivr.net/gh/cysharp/memorypack@main/README.md))
- [Buffer-Reusing Serializers](https://awesome-repositories.com/f/software-engineering-architecture/zero-copy-buffers/zero-allocation-buffer-encoders/buffer-reusing-serializers.md) — Minimizes garbage collection pressure by reusing existing object instances during the deserialization process.
- [Zero-Encoding Binary Formats](https://awesome-repositories.com/f/software-engineering-architecture/zero-encoding-binary-formats.md) — Writes data directly to binary streams without intermediate transformation to achieve maximum processing throughput.
- [Collection Streaming](https://awesome-repositories.com/f/software-engineering-architecture/channel-based-stream-processing/collection-streaming.md) — Processes massive object arrays using asynchronous streams to prevent high memory consumption.

### Networking & Communication

- [Payload Compressions](https://awesome-repositories.com/f/networking-communication/payload-compressions.md) — Reduces binary size using compression algorithms to minimize the volume of data transmitted across the network. ([source](https://cdn.jsdelivr.net/gh/cysharp/memorypack@main/README.md))

### Web Development

- [Unity Serialization Libraries](https://awesome-repositories.com/f/web-development/cross-platform-development/game-development-frameworks/unity-game-development-toolkits/unity-serialization-libraries.md) — Optimizes Unity game state persistence by using fast binary serialization for reduced load times.

### Part of an Awesome List

- [Serialization Libraries](https://awesome-repositories.com/f/awesome-lists/devtools/serialization-libraries.md) — Zero-copy binary serialization for .NET.
