Interface IWritableMemorySource
- Namespace
- CStructSharp.Memory
- Assembly
- CStructSharp.dll
A source that can also replace bytes in place. A successful write changes every requested byte; a failed one may have changed some.
public interface IWritableMemorySource : IMemorySource
- Inherited Members
Remarks
Writing is a separate interface from reading so that an analyzer can hand a read-only capture to code that only needs IMemorySource without accidentally offering a way to modify it. MemoryPatch checks for this interface at commit time, which is why a patch can be previewed against any source but only committed to a writable one.
Write(ulong, ReadOnlySpan<byte>, MemoryAccessContext) has no partial-success return value: either the whole span was written or an exception was thrown. An exception, however, may arrive after some bytes were already changed (a transport can fail halfway). This is the reason Commit(MemoryAccessContext?) reports its failing fragment as uncertain and never promises rollback. Implementations keep ownership of their storage and must advance Generation after every observable mutation so caches and staged patches can detect the change.
Methods
Write(ulong, ReadOnlySpan<byte>, MemoryAccessContext)
Replaces bytes starting at address. The range must already exist; writing never extends a source.
void Write(ulong address, ReadOnlySpan<byte> bytes, MemoryAccessContext context)
Parameters
addressulongUnsigned start address in this source's own coordinate system.
bytesReadOnlySpan<byte>Replacement bytes; the source copies them and does not retain the span.
contextMemoryAccessContextShared budget and cancellation for the operation; the write charges its byte count.
Exceptions
- MemoryAccessException
The range is outside the source, the budget is exhausted, or the source state prevents the write.
- OperationCanceledException
Cancellation was requested before the write.