Any questions from a PROFI to a SUPER PROFI - 1. - page 28

 
    // 2.2.6. Метод меняет размер отведённой памяти для файлового отображения. Метод в случае успешного завершения возращает TRUE или FALSE в случае ошибки.
    bool Resize(const DWORD64 dw64BytesMapping) // Количество резервируемой памяти для файлового отбражения.
     {
      DWORD         dwErrorCode = 0; // Последняя ошибка.
      tstringstream ssExclusion;     // Строка с сообщением об ошибке.
      dw64Bytes = dw64BytesMapping;
      ::SetLastError(0); // Сбрасываем последнюю ошибку.
      // Контроллируем на наличие дескриптора файла и имени файлового отображения.
      if (hFile == NULL && sName == _T(""))
       {
        if (DEBUGGING || DEBUGGING_EXCLUSION)
         {
          ssExclusion << std::endl << _T("Ошибка в методе \"Utils::MappingSTL::Resize()\".")
                      << std::endl << _T("Отсутствуют дескриптор пользовательского")
                      << std::endl << _T("файла и имя файлового отображения.") << std::endl;
          if (DEBUGGING) tcout << ssExclusion.str();
          if (DEBUGGING_EXCLUSION) throw(ssExclusion.str());
         }
        return(false);
       }
      // Создаем или открываем уже существующее отображение файла по дескриптору пользовательского файла.
      vhMapping.push_back(::CreateFileMapping(hFile, NULL, PAGE_READWRITE, Utils::FILESIZE64(dw64Bytes).dwSizeHigh, Utils::FILESIZE64(dw64Bytes).dwSizeLow, sName.c_str()));
      // Если получен не верный указатель на файловое отображение.
      if (vhMapping.back() == NULL)
       {
        if (DEBUGGING || DEBUGGING_EXCLUSION)
         {
          dwErrorCode = ::GetLastError(); // Получаем последнюю ошибку.
          ssExclusion << std::endl << _T("Ошибка в методе \"Utils::MappingSTL::Resize()\".")
                      << std::endl << _T("Размер памяти файлового отображения \"") << sName << _T("\" не изменён.")
                      << std::endl << LAST_ERROR_PARAMETER(dwErrorCode) << std::endl;
          if (DEBUGGING) tcout << ssExclusion.str();
          if (DEBUGGING_EXCLUSION) throw(ssExclusion.str());
         }
        return(false);
       }
      return(true);
     }
This is a method from the mapping class.
 
Zhunko:
It's a method from a mapping class.

So what?

The topic of mapping resizing is not covered.

 
That's what I do.
 
Zhunko:
That's what I do.

I.e. when you open a mapping with the same name and a different size, it changes size?

You don't have to answer, it's not in the code anyway. What you do there is little to do with the question :) so good luck.

 

Of course it does. I have a library on this class that works. The tests are fine. The first variant of this library is in the piggy bank.

The latest version of the library itself changes size depending on need.

 
TheXpert:

So when you open a mapping with the same name and a different size it changes size?

You don't have to answer, that's not what's in the code anyway. What you do there has little to do with the question :) so good luck.

Andrew, I rechecked two ways.

Well, yes. When you call CreateFileMapping with the same name but with a larger size, the memory is expanded.
The main thing is that the first handle of CreateFileMapping should not be closed (just to avoid losing previous contents).


But! In the second case I tested a more interesting hypothesis.

A CreateFileMapping is created with an initial size (e.g. 2 bytes) and 4 bytes are written to it. And it automatically expands itself!

So there is no need to create a second CreateFileMapping handle with a larger size.

I think the question is closed.
 
sergeev:

But! The second case tested the hypothesis more interestingly.

CreateFileMapping is created with an initial size (e.g. 2 bytes) and 4 bytes are written to it. And it automatically expands itself!

So there is no need to create a second CreateFileMapping handle with larger size.

I think the question is closed.
It's in the description. It's handy, but it only increases in size. Takes up resources. You have to make your own memory manager.
 
Zhunko:
It's in the description.

In the description of what? That's what I need to get my memory up.
 
sergeev:

In the description of what? I need it to be freed.

MSDN :-))

I mean, if memory consumption increases, you have to release it.

 
when closing the handle, isn't the memory (which has been allocated over and above that specified in CreateFileMapping) not reverted back?
Reason: