Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7637983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:03:58+00:00 2026-05-31T08:03:58+00:00

How can I reserve and allocate shared memory without the backing of a file?

  • 0

How can I reserve and allocate shared memory without the backing of a file? I’m trying to reserve a large (many tens of GiBs) chunk of shared memory and use it in multiple processes as a form of IPC. However, most of this chunk won’t be touched at all (the access will be really sparse; maybe a few hundred megabytes throughout the life of the processes) and I don’t care about the data when the applications end.

So preferably, the method to do this should have the following properties:

  1. Doesn’t commit the whole range. I will choose which parts to commit (actually use.) (But the pattern is quite unpredictable.)
  2. Doesn’t need a memory-mapped file or anything like that. I don’t need to preserve the data.
  3. Lets me access the memory area from multiple processes (I’ll handle the locking explicitly.)
  4. Works in both Linux and Windows (obviously a 64-bit OS is needed.)
  5. Actually uses shared memory. I need the performance.
  6. (NEW) The OS or the library doesn’t try to initialize the reserved region (to zero or whatever.) This is obviously impractical and unnecessary.

I’ve been experimenting with boost::interprocess::shared_memory_object, but that causes a large file to be created on the filesystem (with the same size as my mapped memory region.) It does remove the file afterwards, but that hardly helps.

Any help/advice/pointers/reference is appreciated.

P.S. I do know how to do this on Windows using the native API. And POSIX seems to have the same functionality (only with a cleaner interface!) I’m looking for a cross-platform way here.

UPDATE: I did a bit of digging, and it turns out that the support that I thought existed in Windows was only a special case of memory-mapped files, using the system page file as a backing. (I’d never noticed it before because I had used at most a few megabytes of shared memory in the past projects.)

Also, I have a new requirement now (the number 6 above.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:03:59+00:00Added an answer on May 31, 2026 at 8:03 am

    On Windows, all memory has to be backed by the disk one way or another.

    The closest I think you can accomplish on windows would be to memory map a sparse file. I think this will work in your case for two reasons:

    1. On Windows, only the shared memory that you actually touch will become resident. This meets the first requirement.
    2. Because the file is sparse, only the parts that have been modified will actually be stored on disk. If you looked at the properties of the file, it would say something like, “Size: 500 MB, Size on disk: 32 KB”.

    I realize that this technically doesn’t meet your 2nd requirement, but, unfortunately, I don’t think that is possible on Windows. At least with this approach, only the regions you actually use will take up space. (And only when Windows decides to commit the memory to disk, which it may or may not do at its discretion.)

    As for turning this into a cross-platform solution, one option would be to modify boost::interprocess so that it creates sparse files on Windows. I believe boost::interprocess already meets your requirements on Linux, where POSIX shared memory is available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like (in *nix) to allocate a large, contigious address space, but without
i'm trying tocreate a biding system with this structure : users can reserve an
I'm developing a simple Wedding List application, where guests can reserve the present they
vector<vector<string> > test for example. g++, you can do test.reserve(10); test[0] = othervector; test[9]
Can anyone help with this... vector<unsigned int> *vVec = new vector<unsigned int>; vVec .reserve(frankReservedSpace);
Anyone have any ideas what I can do? Please reserve commenting about using 1.1
My WPF .net application seems to leak memory (I also use native and 3rd
Let's std::vector myVec; myVec.reserve(10); If I allocated only 5 elements, how can I regain
Im trying to read some data from a binary file into a buffer allocated
These 2 functions are my attempt to serialize a QVector. Unfortunally I can't use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.