Is writing to &str[0] buffer (of a std:string) well-defined behaviour in C++11?

Yes, the code is legal in C++11 because the storage for std::string is guaranteed to be contiguous and your code avoids overwriting the terminating NULL character (or value initialized CharT). From N3337, ยง21.4.5 [string.access] const_reference operator[](size_type pos) const; reference operator[](size_type pos); 1 Requires: pos <= size(). 2 Returns: *(begin() + pos) if pos < size(). … Read more

Are strings mutable in Ruby?

Yes, << mutates the same object, and + creates a new one. Demonstration: irb(main):011:0> str = “hello” => “hello” irb(main):012:0> str.object_id => 22269036 irb(main):013:0> str << ” world” => “hello world” irb(main):014:0> str.object_id => 22269036 irb(main):015:0> str = str + ” world” => “hello world world” irb(main):016:0> str.object_id => 21462360 irb(main):017:0>

Is there a memory-efficient replacement of java.lang.String?

With a Little Bit of Help From the JVM… WARNING: This solution is now obsolete in newer Java SE versions. See other ad-hoc solutions further below. If you use an HotSpot JVM, since Java 6 update 21, you can use this command-line option: -XX:+UseCompressedStrings The JVM Options page reads: Use a byte[] for Strings which … Read more

Extending builtin classes in python

Just subclass the type >>> class X(str): … def my_method(self): … return int(self) … >>> s = X(“Hi Mom”) >>> s.lower() ‘hi mom’ >>> s.my_method() Traceback (most recent call last): File “<stdin>”, line 1, in <module> File “<stdin>”, line 3, in my_method ValueError: invalid literal for int() with base 10: ‘Hi Mom’ >>> z = … Read more