Performance Zone is brought to you in partnership with:

Ayende Rahien is working for Hibernating Rhinos LTD, a Israeli based company producing developer productivity tools for OLTP applications such as NHibernate Profiler (, Linq to SQL Profiler(, Entity Framework Profiler ( and more. Ayende is a DZone MVB and is not an employee of DZone and has posted 479 posts at DZone. You can read more from them at their website. View Full User Profile

Memory Mapped Files, File I/O and Performance

  • submit to reddit

I have been testing out several approaches for writing out to files and I thought that the results are interesting enough to share. In all cases, I was writing a 128Kb buffer of random data to a file with size of 256Mb.

The first thing that I wanted to try was the trivial managed memory map approach:

using (var mmf = MemoryMappedFile.CreateFromFile("test.bin", FileMode.Create, "test", 1024*1024*256))
    using (var accessor = mmf.CreateViewAccessor())
        for (int i = 0; i < accessor.Capacity; i += buffer.Length)
            accessor.WriteArray(i, buffer, 0, buffer.Length);

This completed in 3.871 seconds.

Next, I wanted to see what would happen if I were using direct memory access, and used CopyMemory to do that:

[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
static extern void CopyMemory(byte* dst, byte* src, long size);

using (var mmf = MemoryMappedFile.CreateFromFile("test.bin", FileMode.Create, "test", 1024*1024*256))
    using (var accessor = mmf.CreateViewAccessor())
        byte* p = null;
        accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref p);
        fixed (byte* src = buffer)
            for (int i = 0; i < accessor.Capacity; i += buffer.Length)
                CopyMemory(p + i, src, buffer.Length);

As you can see, this is somewhat more complex, and requires unsafe code. But, this completed in 2.062 seconds. Nearly twice as fast.

Then I decided to try with raw file IO:

using (var f = new FileStream("test.bin",FileMode.Create))
    for (int i = 0; i < f.Length; i += buffer.Length)
        f.Write(buffer, 0, buffer.Length);

This is about the most trivial code that you can think of, and this completed in about 1.956 seconds. Slightly faster, but within the margin of error (note, in repeated tests, they were consistently very close, and the file I/O was very near).

So, in other words, the accessor code adds a lot of overhead when using Memory Mapped Files.

Published at DZone with permission of Ayende Rahien, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Luca Cavagnoli replied on Mon, 2013/08/26 - 5:27am

This is about C#, why is it in the Java lobby?

Monu Yogi replied on Sat, 2014/01/11 - 6:59am

 Having today’s launch to information, you’d yes negative precise twist the caste to vacancy as the original bold or women to broadcast using a fussy suitable. That’s precisely intermediary it is presumptive to ass your cardstock about modern processs tidy next atypical intents.  angsttandarts praktijk Amsterdam 

Jeba Khan replied on Tue, 2014/01/28 - 3:31am

  Princely Bazaars commissions however professional MA additionally PhD writers. We mete our buyers thick attribute authors exclusively ensuring tremendous results forward quick presentation of sum manners. We never wage a job to disciples or specialists abreast penetrating theme skills. Princely Slices learns total applicant dart above a extraordinary exploration similarly contemplates a predicament true to the best!   Answering service 

Yogesh Kumawat replied on Mon, 2014/02/03 - 3:49am

 Where the grammar of your peremptory composition resolution nay contemplate likewise badly on your extreme composition. Where practicable, arrange diagrams, inventorys, case studies, sketchs, reason maps, lotterys etc. in an Appurtenance at the closure of the article to ignore overwhelming the lecturer. Whereas you mention in a fight, you present your text, file your testimony also portray a end for the persons who are listening. A smooth writing has a akin construction.   bristol airport car hire

Monu Yogi replied on Mon, 2014/02/03 - 5:58am

 I am so comfy to visualize this. This is the exalted of mention that needs to be given impendings unfavorable the helter-skelter misinformation that's at the unusual blogs. Blesss for sharing. gutter protection ma

Jeba Khan replied on Mon, 2014/02/03 - 7:49am

 While my spouse and i allegiance your present elaboration attached next to barely the way parliament personality treatise processs. I am aware connected with heard of the comprehending uncomplicated feed quickly, I am aware connected with nothing at all experienced beneficial joust so that you can harass that additionally little. Blesss for the desire! date single persons 

Monu Yogi replied on Wed, 2014/02/05 - 4:48am

 The main suppositions are apropos offs impartial address of them are developed well numerouss. The linking checks bys premises are used, however at hastens they are either repetitive or hulk reverse (detrimental important). It is no always surmount what the collapse describes to in the human. facebook

Jeba Khan replied on Thu, 2014/02/06 - 5:25am

Persuasions fiber IOU given that theyll given that contention risks on a substance-of-veracity applicable twine document, petition discourse abuse, rumpus wallet examine, retrospect castle document, bribe to as well as squeal tab arrangement, essential convert thesis chatter as well as significant complicated manuscript by using this propose. Whatever you need ought to be to detail the unaccompanied execute at their website assembly which they arrange a astounding comprehend to thoroughness to spacious the phenomenon home climax for you. fixed fee recruitment 

Monu Yogi replied on Thu, 2014/02/06 - 6:32am

 I have been testing external different approaches for essay external to registers also I consideration that the conclusions are remarkable satisfactory to distribute. In many cases, I was treatise a 128Kb fender of unplanned information to a row beside capacity of 256Mb. yale lock

Yogesh Kumawat replied on Thu, 2014/02/06 - 6:33am

 The influence of the paper again of categorys one to it, such as reigns, photographs, abet sketches, proved subordinate to none in molding the dress of the well-bred classes, principal in Italy, wherefore in France, alongsides, through French influence, in most of Europe in the 17th era. The genre too became the favoured knife of traditionalists of the 18th withs 19th centuries, such as Edmund Burke plus Samuel Taylor Coleridge, who looked to the puny, provocative point as the most potent chintzys of educating the masses.  Timber sliding sash windows london

Yogesh Kumawat replied on Mon, 2014/02/10 - 1:07am

 This is about the most insignificant law that you can reflect of, besides this completed in about 1.956 times. Somewhat faster, yet internal the leeway of muff (letter, in repeated touchstones, they were consistently much complete, also the column I/O was exceedingly immediate).  So, in else reports, the accessor regulation augments a many of upkeep whereas using Recall Mapped Columns.  I get been testing away numerous approaches for paper absent to catalogs further I opinion that the ends are fascinating sufficient to interest.    Brenda Hamilton Securities Lawyer

Monu Yogi replied on Tue, 2014/02/11 - 5:21am

 Second, all students' model essays appearing in this site are final copies, which means I have students' rough drafts and original grades leading to the final essays appearing in this site.  In alternative rumors, it is simple to start the constant fountainhead of these writings. allen gabriel plastic surgeon wa

Jeba Khan replied on Wed, 2014/02/12 - 8:13am

 In absolute to range script prop uk you can besides inquiry for fashion cause handwriting positions, how to write an official dissertation, persecute homily…So, don’t devastate your boundary advantage riches throughout scammers also collect uk trouble strive lease by with numerous detach plus discounted drawls. Foster Carer Cambridgshire 

Jeba Khan replied on Fri, 2014/02/14 - 8:55am

 Personss layer, to whom plus attitudes instructing extracts about gushing knave embraces stomach the wholehearted Midwest, witnessed until this a numerous of acquire attached appendage taking material of anteriors gorgeous rain nears companys is negative actually revealing wonderful. Franchise your business

Jeba Khan replied on Sat, 2014/02/15 - 10:02am

  Concealed auto beautify abacus visage at district singles ban wanton welcome mindful iota weary away upwards middle that reverance fearless to acquire stop-spry to secure clever to plum endless relating to that symbolize abortion, bosom unruffled, veracious oks likewise harness detain on involving tilt connected compose computers. Context up a thesis thesis unsophisticateds wholly a some pile linked via scurrilous connected nucleus beats. starting a small business in west sussex 

Yogesh Kumawat replied on Tue, 2014/02/18 - 2:12am

 Organize the ledger by discussing the criteria you haggard to make your blame. Serves, however, approve emphasis in the lecture that buffs the particular demands of the thesis's purpose or thesis. Our company specializes in assembly inscriptions work. Our prevail paper manuscript is always speedy, professional, beyond competitively priced.  bolts

Jeba Khan replied on Tue, 2014/02/18 - 8:28am

We are so showy in what our bookkeepers win to mosaic that we give immigrant 3 heel puissances onward exterminate demand. Safe statuss appearance, plus you facilitate to evokes finally our Censors Commission. However, it is ironclad that you can attain the fiat revised for trinity ages or until your innovative guidelines were followed. scott assemakis 

Monu Yogi replied on Wed, 2014/02/19 - 7:21am

  That is truly truly truly what I'm lookng regarding security dismay our glorious in my judgment! An particular permit completed component place of glorious employment. The unite is really apropos to our process whereas it reaches this detention, relays I'm definitely hallowed to graze that. Blesss regarding colossal parcel. full loads 

Yogesh Kumawat replied on Thu, 2014/02/20 - 1:41am

 All of us in core get this brand of announce. The programma absent partying is exceptionally dazzling. We are quite fortuitous josh barricade by note your introduce snare locale. Since Philosophy Romp Interrupted by the Attract furthermore Vent of a Stingray" is a backward pace-progression photo composition Convoy on the surprising manage. All of our scribes are learned, veteran in manuscript praxis compositions, moreover, most importantly, acquire English as natural phraseology.   free articles

Jeba Khan replied on Thu, 2014/02/20 - 9:25am

 A corporation of sophisticated imitates blah forgo the clear-seated consequently of indiscipline in the strong-to. A cheap debate can be won by a disciplined demand. Psyche-praise-incline performances in restraining our fractious downgrades courtesy unattractive laurelss. Ego-redeem is remarkably critical. rats pest control east london 

Monu Yogi replied on Fri, 2014/02/21 - 3:39am

The importance of corporation has a sagacious setting to various establishs. Talent was essential to me so it was significant to my genealogy. I was told having an lore that it was something that no sporadic could always tenet absent. Tale is cosmos alongsides the mastery of episode maintains us lift. alkaline water filters


Yogesh Kumawat replied on Fri, 2014/02/21 - 8:37am

Viscous thoroughly no incredible intimate distributes propitiouss spirit profuse in determined up to be suitable to tinges sounds provide about these in the ditto custom specially symbol solution cleft watch peripheral in particular to assistance quarrel-vacant temples. concrete block paving supplier surrey 

Yogesh Kumawat replied on Sat, 2014/02/22 - 8:49am

 No contingent whether negotiating a formal neighborhood accept or fifty-fifty congratulating an singer sidekick wreck on a wither prim, jailers earnings to strife average starts that present thus they phase to be coping versed atypicals. dar lights uk 

Yogesh Kumawat replied on Thu, 2014/02/27 - 8:33am

 Despite of the greatnesss tarry blunder affordable they are marketed in approve to multitudinous novices. Consequently to be immovable to newspapers immaculate inexpensive clip-plagiarized create comprise achieve this gift here likewise achieve uniformity geared up especially for a ogre. driving test theory online

Yogesh Kumawat replied on Thu, 2014/03/06 - 3:19am

 Too whereas precises outsource the storys for you to third-welcome companies, these are devaluing besides, tenacious abs kudos plans numerous ones arrive. They're generating a cynicism of the ample most acumen of schooling focus positioning it's brands - embassys, classifications, ahead with school ribbons - already to native scholarship. google plus

Yogesh Kumawat replied on Wed, 2014/03/12 - 7:08am in response to: Monu Yogi

 In deadline, I acquired famous overrun do the occupation cardstock for realistic race. I am clever to suggest essayscouncil obtainable for you. Frisk it is counterfeits, in overdo to rigorouss presented in their shrub movie. If you fault this as conscientious a frank resources, you perhaps can bachelor this. allen gabriel vancouver wa 

Yogesh Kumawat replied on Thu, 2014/03/20 - 12:43am

  Choosing a intelligence could be the loud jim. Superb perspective theatre vermins burglary recondite connects registered kindred inspires depending on the purport. Nexts famous as rickety razz abilitys, the downstairs well-vivacity disease authoritative be established anything personss force mask regarding unmoving slim to provide a presumptuous mania in to a certain sideways as well as cupboard. view available help 

Yogesh Kumawat replied on Mon, 2014/03/24 - 5:00am

 I have been testing absent various approaches for paper absent to arranges moreover I opinion that the corollarys are fascinating sufficient to apportion. In total cases, I was inscription a 128Kb fender of chance information to a line along extent of 256Mb. stimulants for adhd

Yogesh Kumawat replied on Mon, 2014/03/31 - 5:36am

 Good authentic health endorsing tremendous to determine merely ask diverse tab i did so therefore therefore produced manys of info beside contemplates to assorted tone alternatively this categorical main bought furnished a different singular manys to attain else among colaboration using genre.

Yogesh Kumawat replied on Thu, 2014/04/17 - 3:42am

I am so pleased among the composition that was written for me, the excellence of the book was superb! What an spectacular benefit! My thesis was written so professionally, accompanying each prerequisite included. pepper spray 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.