Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

[core] Replace boost iostream with std::{i,s}stream - #5417

Merged
brunoabinader merged 1 commit into
masterfrom
brunoabinader-stringstream
Jun 21, 2016
Merged

brunoabinader merged 1 commit into
masterfrom
brunoabinader-stringstream

Conversation

@brunoabinader

Copy link
Copy Markdown
Contributor

@brunoabinader brunoabinader added the Core The cross-platform C++ core, aka mbgl label Jun 21, 2016
@springmeyer

Copy link
Copy Markdown
Contributor

👍

@brunoabinader
brunoabinader merged commit b06176c into master Jun 21, 2016
@jfirebaugh

Copy link
Copy Markdown
Contributor

🙇

@jfirebaugh
jfirebaugh deleted the brunoabinader-stringstream branch June 21, 2016 16:18
PremultipliedImage decodePNG(const uint8_t* data, size_t size) {
source_type source(reinterpret_cast<const char*>(data), size);
input_stream stream(source);
std::istringstream source(std::string(reinterpret_cast<const char*>(data), size));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ creates a new std::string and copies data!

@artemp

artemp commented Jun 22, 2016

Copy link
Copy Markdown
Contributor

Better solution is to implement custom stream buffer : https://artofcode.wordpress.com/2010/12/12/deriving-from-stdstreambuf/
/cc @brunoabinader @jfirebaugh @springmeyer

@artemp

artemp commented Jun 22, 2016 •

Copy link
Copy Markdown
Contributor

@brunoabinader This is what II did in mapnik mapnik/mapnik@2e8c0d3
Note: for tiff_reader to work correctly stream buffer must implement

pos_type seekoff( off_type off, ios_base::seekdir dir,
                     ios_base::openmode which = ios_base::in | ios_base::out );

http://en.cppreference.com/w/cpp/io/basic_streambuf/pubseekoff

/cc @springmeyer @jfirebaugh

@jfirebaugh

Copy link
Copy Markdown
Contributor

@artemp I was wondering about that, thanks for the links.

@mb12

mb12 commented Jun 22, 2016

Copy link
Copy Markdown

@artemp and @jfirebaugh Is the concern here that duplicate copy of image data in std::string can cause performance issue? This may not be perceptible to the end user at all esp for Vector maps where this code will kick in only once when loading the sprite. #3048 is more likely to be a performance bottleneck arising due to copying data multiple times (But it has not been measured).

When we switched from Curl to OkHttp for network access, it introduced multiple copies of tile data as it moves across JNI boundary. (Issue #3048).

#3048

@brunoabinader

Copy link
Copy Markdown
Contributor Author

Thank you @artemp - I wonder if we could add char_array_buffer on its own header-only library so we could share code and avoid duplication? /cc @jfirebaugh

brunoabinader added a commit that referenced this pull request Jun 30, 2016
Implements a custom std::streambuf to avoid creating temporary
std::string objects and thus optimizing image decode.

Suggested by @artemp in
#5417 (comment).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Core The cross-platform C++ core, aka mbgl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants