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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:12:13+00:00 2026-05-28T08:12:13+00:00

A quick preface, I’m very comfortable in .Net, but have limited experience in c++,

  • 0

A quick preface, I’m very comfortable in .Net, but have limited experience in c++, so I’m not sure if I’m doing this well.
I’m using a file mapping object to retrieve what could potentially be a relatively long string, comprised of up to several thousand file names. This function can be called from an ImageOverlayHandler attached to Windows explorer, so both speed and memory consumption are of concern. This code could potentially be called by hundreds of overlay requests at once (but only in edge cases). In the code below, is this an efficient way to do this? Using this approach, if I’ve understood my code correctly, I will not make a local copy of the mapped file, and the boost::contains call should be pretty quick. Any thoughts on either how I can improve it, or how I should do it differently? in a previous iteration I was using vectors, etc, but that seemed like it would use a lot more memory.

HRESULT GetFolders()
{
    HANDLE hMapFile;
    LPCWSTR pBuf;
    hMapFile = OpenFileMapping(
               FILE_MAP_ALL_ACCESS,   // read/write access
               FALSE,                 // do not inherit the name
               szFolderName);               // name of mapping object

    if (hMapFile == NULL)
    {
       return NULL;
    }
    pBuf = (LPCWSTR) MapViewOfFile(hMapFile, // handle to map object
           FILE_MAP_ALL_ACCESS,  // read/write permission
           0,
           0,
           BUF_SIZE);

    if (pBuf == NULL)
    {
       CloseHandle(hMapFile);

       return NULL;
    }

    wstring resOut = (wstring)pBuf;

    bool val = boost::contains(resOut, L"C:\\FOLDER1");
    UnmapViewOfFile(pBuf);
    CloseHandle(hMapFile);
}
  • 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-28T08:12:13+00:00Added an answer on May 28, 2026 at 8:12 am

    If you’re creating the list of filenames once or only occasionally and testing it repeatedly, you could benefit from a binary search. A binary search requires two things: the input list must be sorted, and you must be able to index into any element of the list efficiently.

    You can fulfill the first requirement by sorting the list in C# before you write it to the file. You can fulfill the second requirement by creating a list of integers that represent the offset into the string for the start of each filename. Since each integer is the same size it can be indexed, and it’s one simple indirection to get to the actual filename.

    The std::equal_range algorithm will do a binary search. If the returned iterators are equal, the item wasn’t found, otherwise the first iterator points to it.

    You’ll need a custom comparator function to pass to equal_range to do the indirection on the string.

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

Sidebar

Related Questions

Quick Question. Eval in JavaScript is unsafe is it not? I have a JSON
Quick question: If I have a very large function/sub in a class that is
Quick edit: As was pointed out below I should be doing a BFS but
Quick question. What do you think, I have a few sites that use a
Quick one, but thought I'd ask. Is there a better way of getting the
Quick question. There is a legacy website (that is not under my control and
Quick question about the TransactionScope object. Found this on the internet: When you access
Quick question: is this kind of nesting possible? An if statement first passing a
Quick question that requires a long explanation.. Say I have two tables - one
Quick question - I've finished building an outlook add-in in VS2010, .NET 4.0. I

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.