I explore Memory Mapped File (MMF) and here is what I have done so far just following example on MSDN http://msdn.microsoft.com/en-us/library/dd997372.aspx
class MMF {
private long offset = 0x10000000; // 256 megabytes
private long length = 0x20000000; // 512 megabytes
public MMF() {
using (var mmf = MemoryMappedFile.CreateFromFile(@"c:\NFS", FileMode.Open, "NMAP")) {
using (var accessor = mmf.CreateViewAccessor(offset, length)) {
int fsSize = Marshal.SizeOf(typeof(FS));
FS nfs;
// Make changes to the view.
for (long i = 0; i < length; i += fsSize) {
accessor.Read(i, out nfs);
accessor.Write(i, ref nfs);
where FS is just array of another class objects
public class FS {
public NFS[] files;
}
but I'm getting error:
The type 'NEN_Server.FS.FS' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.IO.UnmanagedMemoryAccessor.Read(long, out T)'
What am I doing wrong? Must my class to be non-nullable or should I use accessor in another way?
thank you
The keyword here is not "non-nullable", but "valuetyp". You're supposed to declare a struct
for the data you want to read/write, not a class
. The addition "non-nullable" only means you can't use foo?
instead of foo
.