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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:15:32+00:00 2026-05-18T07:15:32+00:00

I wrote a generic in-memory B+Tree implementation in C++ few times ago, and I’m

  • 0

I wrote a generic in-memory B+Tree implementation in C++ few times ago, and I’m thinking about making it persistent on disk (which is why B+Tree have been designed for initially).
My first thought was to use mmap (I’m under Linux) to be able to manipulate the file as normal memory and just rewrite the new operator of my nodes classes so that it returns pointers in the mapped portion and create a smart pointer which can convert RAM adresses to file offset to link my nodes with others.
But I want my implementation to be generic, so the user can store an int, an std::string, or whatever custom class he wants in the B+tree.
That’s where the problem occurs: for primitive types or aggregated types that do not contain pointers that’s all good, but as soon as the object contains a pointer/reference to an heap allocated object, this approach no longer works.

So my question is: is there some known way to overcome this difficulty? My personnal searches on the topic end up unsuccessful, but maybe I missed something.

  • 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-18T07:15:33+00:00Added an answer on May 18, 2026 at 7:15 am

    As far as I know, there are three (somewhat) easy ways to solve this.

    Approach 1: write a std::streambuf that points to some pre-allocated memory.

    This approach allows you to use operator<< and use whatever existing code already exists to get a string representation of what you want.

    • Pro: re-use loads of existing code.
    • Con: no control over how operator<< spits out content.
    • Con: text-based representations only.

    Approach 2: write your own (many times overloaded) output function.

    • Pro: can come up with binary representation.
    • Pro: exact control over every single output format.
    • Con: re-write so many output functions… writing overloads for new types by clients is a pain because they shouldn’t write functions that fall in your library’s namespace… unless you resort to Koenig (argument dependant) lookup!

    Approach 3: write a btree_traits<> template.

    • Pro: can come up with binary representation.
    • Pro: exact control over every single output format.
    • Pro: more control on output and format that a function, may contain meta data and all.
    • Con: still requires you / your library’s users to write lots of custom overloads.
    • Pro: have the btree_traits<> detault to use operator<< unless someone overrides the traits?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a generic Parse method that converts and returns a
I'd like to write a generic method that creates a new instances of a
What would be the best way to write a generic copy constructor function for
Recently, Lee Baldwin showed how to write a generic, variable argument memoize function .
I write a large static method that takes a generic as a parameter argument.
Wrote the following in PowersHell as a quick iTunes demonstration: $iTunes = New-Object -ComObject
I wrote a simple batch file as a PowerShell script, and I am getting
I wrote a windows service using VB that read some legacy data from Visual
I wrote myself a little downloading application so that I could easily grab a
I wrote a component that displays a filename, a thumbnail and has a button

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.