dart_shared_memory 0.1.1 copy "dart_shared_memory: ^0.1.1" to clipboard
dart_shared_memory: ^0.1.1 copied to clipboard

In-memory key-value stores shared across Dart isolates, with binary values and atomic updates.

example/dart_shared_memory_example.dart

import 'dart:typed_data';

import 'package:dart_shared_memory/dart_shared_memory.dart';

/// Creates, reads, conditionally updates, and deletes a binary value.
void main() {
  final store = SharedStore.open(name: 'quick-start');
  try {
    final created = store.commit(
      checks: {'counter': null},
      changes: {'counter': Uint8List(8)},
    );
    if (!created.committed) throw StateError('Counter already exists');

    final snapshot = store.read(['counter'])['counter']!;
    final bytes = snapshot.value;
    ByteData.sublistView(bytes).setInt64(0, 42);
    final updated = store.commit(
      checks: {'counter': snapshot.revision},
      changes: {'counter': bytes},
    );
    if (!updated.committed) throw StateError('Counter changed concurrently');
    print(
      'Counter: ${ByteData.sublistView(store.read(['counter'])['counter']!.value).getInt64(0)}',
    );

    final deleted = store.commit(
      checks: {'counter': updated.revisions['counter']!},
      changes: {'counter': null},
    );
    print('Deleted: ${deleted.committed}');
  } finally {
    store.close();
  }
}
0
likes
0
points
530
downloads

Publisher

unverified uploader

Weekly Downloads

In-memory key-value stores shared across Dart isolates, with binary values and atomic updates.

Repository (GitHub)
View/report issues

Topics

#ffi #isolates #concurrency #shared-memory

License

unknown (license)

Dependencies

code_assets, ffi, hooks, native_toolchain_c

More

Packages that depend on dart_shared_memory