CCI Metadata is supports non-blocking reading?

Topics: PE reader
Jan 6, 2011 at 4:40 PM

Hi.

 

I'm one of Nemerle developers.

 

We are trying to use CCI Metadata to reading metadata assemblies in IDE integration. We need to read a assembly metadata without blocking the assembly (a compiler should freely overwrite assemblies).

 

CCI Metadata is supports non-blocking reading? Or we should use shadow copying?

Coordinator
Jan 6, 2011 at 5:58 PM

Your metadata reader host class must override the OpenBinaryDocument methods and return documents that read from copies. The default source code for these methods already contains the necessary code, but under conditional compilation. Enable it and remove the use of the memory mapped files. For example:

     public virtual IBinaryDocumentMemoryBlock/*?*/ OpenBinaryDocument(IBinaryDocument sourceDocument) {
      try {
        IBinaryDocumentMemoryBlock binDocMemoryBlock = UnmanagedBinaryMemoryBlock.CreateUnmanagedBinaryMemoryBlock(sourceDocument.Location, sourceDocument);
        this.disposableObjectAllocatedByThisHost.Add((IDisposable)binDocMemoryBlock);
        return binDocMemoryBlock;
      } catch (IOException) {
        return null;
      }
    }


Jan 6, 2011 at 6:52 PM

Thank you.

When release the unmanaged memory block which allocated by CreateUnmanagedBinaryMemoryBlock()?

Coordinator
Jan 6, 2011 at 7:01 PM

The general rule in CCI is that the object that allocates a disposable resource is responsible for cleaning it up. In this case, it is the host and the host will dipose the block when it is itself disposed. You can, of course, choose to implement a method on your host that will dispose binary documents before then.

Jan 6, 2011 at 7:26 PM

I do not get a problem if I call dispose after I lose the reference to IAssembly?

Coordinator
Jan 6, 2011 at 8:15 PM

I'm not sure I understand your question. For what is it worth, calling Dispose more than once on an UnmanagedBinaryMemoryBlock will not cause any problems. Clearly, however, if you call Dipose on the document, the assembly that reads from the document may stop working.

Generally, the rule is to dispose the host as a last cleanup step and to be sure not to retain any references to any object obtained via the host after the host has been disposed.