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

  • Home
  • SEARCH
  • 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 7060227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:19:38+00:00 2026-05-28T04:19:38+00:00

I heard about using a mmap system call for merging two blocks of memory

  • 0

I heard about using a mmap system call for merging two blocks of memory into one continuous with MAP_ANONYMOUS flag, but I can’t find any simple example how to use this trick.

The example on the Wikipedia which implements an optimized circular buffer, is too complicated for me (Circular Buffer article).

Can you give me any usage example for MAP_ANONYMOUS flag?

  • 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-28T04:19:38+00:00Added an answer on May 28, 2026 at 4:19 am

    Based on the clarification you have provided in your comments, it sounds like you are trying to mis two things that have nothing to do with each other.

    void *part1 = malloc(100);
    void *part2 = malloc(250);
    

    You want to manipulate virtual memory so that these two blocks of memory are addressable as 350 contiguous bytes of memory.

    This is not possible. First of all, the blocks of memory you have will in general be neither page-aligned nor page-sized. You can only manipulate virtual memory in page-aligned, page-sized chunks. Secondly, even if you are very lucky and they are page-aligned and page-sized, they probably come from the heap area (the area below brk()). I don’t think you can remap or unmap that area of memory using mremap() or munmap(). (There are alternate implementations of malloc() that get memory from mmap() and wouldn’t be subject to this problem but they are still subject to the first problem.

    But let’s say you do have two blocks of memory that are page-aligned, page-sized, and remapable, and you want to remap them so that they are adjacent. Most likely, you obtained those blocks from mmap() in the first place. Then you could remap them to adjacent addresses using mremap(). Be aware that mremap() is Linux-specific though. I’m not aware of a portable way to do this. In pseudocode:

    /* Map some useless memory just to get the kernel to reserve a range
       of addresses for us which will be big enough for both blocks */
    address = mmap(NULL, blocksize1+blocksize2, ..., MAP_ANONYMOUS, ...);
    
    /* remap the first block to the the first address in this new range */
    mremap(block1, blocksize1, blocksize1, MREMAP_MAYMOVE|MREMAP_FIXED, address);
    /* remap the second block to go right after the first block */
    mremap(block2, blocksize2, blocksize2, MREMAP_MAYMOVE|MREMAP_FIXED,
            address+blocksize1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've heard a lot of good things about using Mylyn in eclipse. How could
I heard about external access of a website using curl by the following code:
I am currently using JQuery and recently heard about RightJS . RightJS seems to
I am using Linq-to-SQL for my projects but i heard about the T4 Template
I have recently heard a lot of people argue about using PHP testing features
I'm going to develop a web application using SmartGWT. I've heard about Vaadin framework.
I've heard (on a podcast) about using Silverlight to do client-side validation on an
Now i am using apache2, but i heard about engine-x (nginx) is pretty fast
Hi i have heard lot about using frameworks for creating native app .i want
I'm using Visual studio (sometimes resharper) to run my unit test. I heard about

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.