Skip to content

Instantly share code, notes, and snippets.

Avatar

alf-p-steinbach

View GitHub Profile
@alf-p-steinbach
alf-p-steinbach / app-manifest.xml
Last active May 27, 2020
Demo of Windows API level coding
View app-manifest.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity type="win32" name="Demo of Windows API level coding" version="1.0.0.0"/>
<application>
<windowsSettings>
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings"
>UTF-8</activeCodePage>
</windowsSettings>
</application>
<dependency>
@alf-p-steinbach
alf-p-steinbach / c++-figure.svg.cpp
Last active Apr 24, 2020
SVG graphics via cout (the C curve)
View c++-figure.svg.cpp
#include "draw_c_curve_on.hpp" // draw_c_curve_on
namespace g = graphics;
#include "util-string_from.hpp"
using util::string_from;
#include <iostream>
#include <string>
using std::cout, std::endl, std::ostream,
std::string;
@alf-p-steinbach
alf-p-steinbach / char_bitmap.hpp
Created Mar 3, 2020
C++ "Hello, world!" with asterisk glyphs
View char_bitmap.hpp
#pragma once
// Based on a header generated with GIMP, using Courier New font size 11.
// 8x14 cells, ASCII range 32 through 127.
namespace char_bitmap {
using Byte = unsigned char;
const int cell_width = 8;
const int cell_height = 14;
const int char_height = 9;
@alf-p-steinbach
alf-p-steinbach / lenna.hpp
Last active Jan 19, 2020
Gdi+ bitmap from base-64 encoded data
View lenna.hpp
#pragma once
#include <string_view> // std::string_view
//---------------------------------------- Lenna image scaled down to 51x51:
namespace lenna {
using std::string_view;
const auto& data_literal = R"(
iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAIAAAC1w6d9AAAABGdBTUEAALGPC/xh
BQAAAAlwSFlzAAAOwwAADsMBx2+oZAAAABh0RVh0U29mdHdhcmUAcGFpbnQubmV0
View coroutine-like-threads.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View strings 1 - Why COW is ungood for std string\strings 1 - Why COW is ungood for std string .md

Why COW was deemed ungood for std::string.

COW, short for copy on write, is a way to implement mutable strings so that creating strings and logically copying strings, is reduced to almost nothing; conceptually they become free operations like no-ops.

Basic idea: to share a data buffer among string instances, and only make a copy for a specific instance (the copy on write) when that instance's data is modified. The general cost of this is only an extra indirection for accessing the value of a string, so a COW implementation is highly desirable. And so the original C++ standard, C++98, and its correction C++03, had special support for COW implementations, and e.g. the g++ compiler's std::string implementations used COW.

So why was that support dropped in C++11?

In particular, would the same reason or reasons apply to a reference counted immutable string value class?

You can’t perform that action at this time.