Memory Mapped Files

A memory mapped file is a disk file (or a part of it) that has been associated to a segment of the virtual memory space of a process. It’s useful when you need to manipulate files that are too large to fit in memory. Once mapped you can access the file as if it was entirely uploaded in memory. In reality the OS is paging the appropriate part of the file as you read from the mapped file pointer.

Benefits

  • It’s faster to access memory mapped files, than to use direct read and write operations;
  • You can use the data without copying it;
  • Ease of use.

Drawbacks

  • You are limited by the process space. On 32-bit versions of Windows typically the applications have 2 GB addressable memory, meaning that you can not map files bigger than 2 GB.

(more…)

Error Handling – The C++ Way

In my experience as software developer, I noticed that there are lots of people that write in C++, but do not use exceptions. They prefer to use return codes instead. I guess that this is caused by the late addition of exceptions in the C++ standard. Whatever the reason is, personally, I prefer to use exceptions as an error handling technique.

Almost 10 years ago I started programing in Object Pascal (Borland Delphi). It was really popular in Bulgaria at that time. I used to like it and I still think that Pascal is the best programming language for education purposes. In my opinion VCL is well designed framework, that is teaching developers good programming practices. Anyway, exceptions are widely used in VCL. So I got used to exceptions and when I moved to C++, I continued using this error handling mechanism.
(more…)