Loading…
<trademark class="registered">UNIX</trademark> allows us to map a file, or a section of a file, into memory. To do that, we first need to open the file with the appropriate read/write flags. Then we use the <function role="syscall">mmap</function> system call to map it into the memory. One nice thing about <function role="syscall">mmap</function> is that it automatically works with virtual memory: We can map more of the file into the memory than we have physical memory available, yet still access it through regular memory op codes, such as <function role="opcode">mov</function>, <function role="opcode">lods</function>, and <function role="opcode">stos</function>. Whatever changes we make to the memory image of the file will be written to the file by the system. We do not even have to keep the file open: As long as it stays mapped, we can read from it and write to it.
<trademark class="registered">UNIX</trademark> این امکان را به ما میدهد تا یک پرونده، یا قسمتی از یک پرونده را نگاشت کنیم. برای انجام آن، ابتدا باید پرونده را با نشانهای خواندن/نوشتن مناسب باز کنیم. سپس از فراخوان سامانهٔ <function role="syscall">mmap</function> برای نگاشت آن در حافظه استفاده میکنیم. یک چیز خوب در مورد <function role="syscall">mmap</function> این است که بهطور خودکار با حافظهٔ مجازی کار میکند: میتوانیم نسبت به حافظهٔ فیزیکی موجودی که داریم قسمت بیشتری از پرونده را در حافظه نگاشت کنیم، اما در عین حال بهواسطهٔ کدهای دستوری معمولی به آن دسترسی داشته باشیم، مانند <function role="opcode">mov</function>، <function role="opcode">lods</function>، و <function role="opcode">stos</function>. هر تغییری که در تصویر حافظهٔ پرونده ایجاد میکنیم از طریق سامانه در پرونده نوشته میشود. حتی نیازی به باز نگاه داشتن پرونده نیست: تا زمانی که نگاشتشده بماند، میتوانیم از آن بخوانیم و در آن بنویسیم.