Application memory for C# and .NET

Run application logic.
Without loading objects.

Memory2 stores typed C# state and lets LINQ query it, change it, and stay subscribed to it before anything is materialized. Build objects only when your code actually needs them.

100Mconnected records in one measured store
29.99M/secrecord updates through the public API
5.23 GBtotal memory for all 100M records

The object is optional.

Most application data gets copied out of storage and rebuilt as objects before code can do anything useful with it. Memory2 does not require that step.

It can filter, calculate, group, rank, update, and react directly against stored typed values. If a caller wants a complete C# object, it can ask for one. Otherwise, the object never needs to exist.

Here is the actual API.

Ask

No objects required.

This total is calculated from stored values. No Payment instances are constructed.

Calculate directlyLINQ
decimal exposure = db.From<Payment>()
    .Where(x => x.Open)
    .Where(x => x.RegionId == "east")
    .Select(x => x.Amount)
    .Aggregate(0m, (total, amount) => total + amount);
Change

Do the work in the store.

The filter and assignments execute as one operation. There is no loop that loads and saves each payment.

Measured result: zero allocation and a 407× median advantage over hydrate–modify–save in the documented two-field workload. See the exact test.
Update every matchone operation
var closePending = db.From<PaymentEvent>()
    .Where(x => x.Pending && x.Amount >= 10_000)
    .PrepareUpdate(x => new PaymentEvent
    {
        Attempts = x.Attempts + 1,
        Pending = false
    });

int changed = closePending.Execute();
Watch

Subscribe to the query.

When a machine enters this result, the callback receives the projected work request. There is no polling loop and no second rules API.

Measured result: 500 live queries remained active during one million writes at 3.46 million writes per second, with zero measured allocation.
A live LINQ querycondition and result
using var response = db.From<MachineState>()
    .Where(x => x.RegionId == "reactor-7")
    .Where(x => x.Enabled && x.Temperature >= 95)
    .Select(x => new WorkRequest
    {
        MachineId = x.Id,
        Priority = Priority.Critical
    })
    .Subscribe(workQueue.Enqueue);

We can do cool stuff like this.

Find a Tire anywhere in the store, change it, and save it. You do not need to load or rewrite the Vehicle around it.

If you later need the vehicle, Memory2 can recover it from the tire.

Work with the exact objectthe parent is optional
Tire tire = db.Query<Tire>()
    .Where(x => x.Color == TireColor.Green)
    .OrderByDescending(x => x.Pressure)
    .First();

tire.Pressure = 34;
db.Save(tire);

Vehicle vehicle = db.Root<Vehicle>(tire);

The 100-million-record run.

Memory2 created one connected store, kept it alive, and used that same state for object reads, LINQ, writes, mixed traffic, deletion, synchronization, save, verification, and restore.

2.4M/secrecords created

Including caller-side object and string construction.

765,794/seccomplete object graphs

Tracked six-object application graphs built for the caller.

29.99M/secrecord updates

Public-API writes with zero measured allocation.

78.49M/seccomplex LINQ

Filter, distinct, rank, window, and sum in one query.

20.44M/secmixed operations

80% reads, 15% queries, and 5% writes.

5.234 GBtotal memory

The complete live store with 24 stored values per record.

3.083 GB saved in 10.945 seconds.The store verified, reopened, and remained queryable.

It survives the process.

Persistence is part of Memory2. Save the state, verify it, reopen it, and continue through the same typed API.

Ordered changes from another process or device report one of four outcomes: applied, already applied, sequence gap, or conflict.

Retries do not duplicate changes. Gaps do not disappear. Conflicts do not silently overwrite newer state.
Save, verify, reopendurable state
using (var db = MemoryStore.Open(stream, leaveOpen: true))
{
    db.Save();

    if (!db.Verify().IsValid)
        throw new InvalidDataException();
}

stream.Position = 0;
using var reopened =
    MemoryStore.Open(stream, leaveOpen: true);

Open source.

Memory2 is released under the MIT License. Use it privately or commercially. Modify it, redistribute it, embed it in a product, or build something new on top of it.

Keep the copyright and MIT permission notice with copies or substantial portions. No separate agreement or permission is required.

Application logic,
close to application state.

Query it. Change it. Subscribe to it. Build an object only when you want one.