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 9131679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:10:45+00:00 2026-06-17T08:10:45+00:00

Possible Duplicate: How to dynamically expand a Memory Mapped File Hi, I have a

  • 0

Possible Duplicate:
How to dynamically expand a Memory Mapped File

Hi, I have a tree-like data structure stored in a memory-mapped file in Windows and when I needed to insert a record I’m checking if it’s free pointer
is closer to the file end. But the real problem is about resizing the file.

In the windows documentation, it is said that `CreateFileMapping’ will resize the file according to its parameters. So I decided to use it as bellow.

#define SEC_IMAGE_NO_EXECUTE 0x11000000

static void resize_file(wchar_t * file_name,int size)
{
  hFile = CreateFile(file_name,GENERIC_READ|GENERIC_WRITE,0,\
                     NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,\
                        NULL);
  if (hFile == INVALID_HANDLE_VALUE)
  {
       MessageBox(NULL,L"resize_file CreateFile have been failed", szAppName,MB_OK);
      exit(0);
  }

  // open file mapping object //
  HANDLE hMap = CreateFileMapping(hFile,NULL,PAGE_EXECUTE_READWRITE|SEC_IMAGE_NO_EXECUTE,0,size,NULL);

  // Close files and mapping //
  CloseHandle(hMap); 
  CloseHandle(hFile);
}

Will this work? I have a little guilty about this because I just open and remap the file and didn’t flush it. Do I need to flush it and do any other operations too?

  • 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-06-17T08:10:46+00:00Added an answer on June 17, 2026 at 8:10 am

    The documentation says two things.

    Firstly (in the "Remarks" section),

    If an application specifies a size for the file mapping object that is larger than the size of the actual named file on disk and if the page protection allows write access (that is, the flProtect parameter specifies PAGE_READWRITE or PAGE_EXECUTE_READWRITE), then the file on disk is increased to match the specified size of the file mapping object. If the file is extended, the contents of the file between the old end of the file and the new end of the file are not guaranteed to be zero; the behavior is defined by the file system.

    This basically means that your file on disk gets resized when you map it to a memory region larger than the file with the call to CreateFileMapping(), and fills it up with unspecified stuff.

    Secondly (in the "Return Value" section),

    If the object exists before the function call, the function returns a handle to the existing object (with its current size, not the specified size), and GetLastError returns ERROR_ALREADY_EXISTS.

    To me, this means your call to resize_file() will have no effect if your file is already mapped. You have to unmap it, call resize_file(), and then remap it, which may or may not be what you want.

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

Sidebar

Related Questions

Possible Duplicate: determine size of dynamically allocated memory in c I have a struct
Possible Duplicate: C dynamically growing array I have a program and I need to
Possible Duplicate: How to dynamically add JLabels to JPanel? I have a created a
Possible Duplicate: Dynamically creating/inserting into an associative array in PHP I have the following
Possible Duplicate: How can i fix my scrollView dynamically when i have more than
Possible Duplicate: How do you execute a dynamically loaded JavaScript block? I have seen
Possible Duplicate: build linq queries dynamically linq update query dynamically I have a method
Possible Duplicate: Remove handlers on disposing object I have some code which dynamically adds
Possible Duplicate: Dynamically loading an external CSS file I'm trying to create a dynamic
Possible Duplicate: Creating tables dynamically in jQuery I have two Arrays, letters = [A,B,C,...]

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.