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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:34:34+00:00 2026-05-31T23:34:34+00:00

I am doing in-memory image conversions between two frameworks (OpenSceneGraph and wxWidgets). Not wanting

  • 0

I am doing in-memory image conversions between two frameworks (OpenSceneGraph and wxWidgets). Not wanting to care about the underlying classes (osg::Image and wxImage), I use the stream oriented I/O features both APIs provide like so:

1) Create an std::stringstream

2) Write to the stream using OSG’s writers

3) Read from the stream using wxWigdets readers

This works fairly well. Until now I’ve been using direct access to the stream buffer, but my attention has been recently caught by the “non-contiguous underlying buffer” problem of the std::stringstream. I had been using a kludge to get a const char* ptr to the buffer – but it worked (tested on Windows, Linux and OSX, using MSVC 9 and GCC 4.x), so I never fixed it.

Now I understand that this code is a time bomb and I want to get rid of it. This problem has been brought up several times on SO (here for instance), but I could not find an answer that could really help me do the simplest thing that could possibly work.

I think the most reasonable thing to do is to create my own streambuf using a vector behind the scenes – this would guarantee that the buffer is contiguous. I am aware that this would not a generic solution, but given my constraints:

1) the required size is not infinite and actually quite predictable

2) my stream really needs to be an std::iostream (I can’t use a raw char array) because of the APIs

anybody knows how I can either a custom stringbuf using a vector of chars ? Please do not answer “use std::stringstream::str()“, since I know we can, but I’m precisely looking for something else (even though you’d say that copying 2-3 MB is so fast that I wouldn’t even notice the difference, let’s consider I am still interested in custom stringbufs just for the beauty of the exercise).

  • 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-31T23:34:35+00:00Added an answer on May 31, 2026 at 11:34 pm

    If you can use just an istream or an ostream (rather than
    bidirectional), and don’t need seeking, it’s pretty simple (about 10
    lines of code) to create your own streambuf using std::vector<char>.
    But unless the strings are very, very large, why bother? The C++11 standard
    guarantees that std::string is contiguous; that a char*
    obtained by &myString[0] can be used to as a C style array.` And the
    reason C++11 added this guarantee was in recognition of existing
    practice; there simply weren’t any implementations where this wasn’t the
    case (and now that it’s required, there won’t be any implementations in
    the future where this isn’t the case).

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

Sidebar

Related Questions

So I am doing some memory analysis on a windows memory image and I
I'm doing a little bit of memory profiling to my software and after running
We are using DevPartners boundchecker for detecting memory leak issues. It is doing a
My project requires me to allocate memory dynamically. What am I doing wrong? /*Setting
Hey all. I'm doing a linked list exercise that involves dynamic memory allocation, pointers,
I've found that all of these scripts, while doing the same thing create memory
I am doing on a project for searching through an image database, and when
Here's what I'm doing now: mysock = urllib.urlopen('http://localhost/image.jpg') fileToSave = mysock.read() oFile = open(rC:\image.jpg,'wb')
With the following code, my browser is returning 'image not created or saved'. I
I am doing image processing in C that requires copying large chunks of data

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.