c# - How to parallel-process data in memory mapped file -
as name of memory mapped file indicates, understand part of large file can mapped memory using class memorymappedfile
in c# fast data process. memory mapped file parallel-process memory mapped. in order that, have following questions
- is
memorymappedfileviewaccessor
thread-safe , parallel.for-safe? made demo program test question , seems working. can't find reference this. if answer yes, done. otherwise, - is there way directly access memory mapped array? know
memorymappedfileviewaccessor
has readarray method using method duplication of memory.
you can reason out. memory mapped file chunk of memory in program bytes accessible more 1 process. pretty awkward in managed code since chunk exists @ specific address. requires accessing data using pointer, taboo in managed code. memorymappedfileviewaccessor wraps pointer, copies data managed memory shared memory. note defeats major reason using mmfs, , why support took long show in .net. sure don't want use named pipes instead.
so reasoning out, mmf isn't thread-safe design since shared memory, global variables in code. things go wrong exact same way if threads read , write same section of shared memory. , have protect against exact same well, lock ensure 1 thread can access shared section.
also note need implement locking between processes read , write mmf. tends painful, have use named mutex "master" process creates , "slave" process opens. cannot skimp on locking requirement. notable never mentioned taking care of in question, red flag there.
within 1 process, threads don't access same section of mmf cannot in each others way. 2 threads access different variables don't require synchronization. long hold mutex ensures process cannot write section. note means want use semaphore protect mmf access, mutex can acquired 1 thread.
Comments
Post a Comment