a minimal String type for Julia that allows for efficient string representation and transfer



An alternative string storage format for Julia

PackageEvaluator Build Status


The package is registered in METADATA.jl and so can be installed with Pkg.add.

julia> Pkg.add("WeakRefStrings")

Project Status

The package is tested against Julia 0.6 and nightly on Linux, OS X, and Windows.

Contributing and Questions

Contributions are very welcome, as are feature requests and suggestions. Please open an issue if you encounter any problems or would just like to ask a question.


A custom "weakref" string type that only points to external string data. Allows for the creation of a "string" instance without copying data, which allows for more efficient string parsing/movement in certain data processing tasks.

Please note that no original reference is kept to the parent string/memory, so WeakRefString becomes unsafe once the parent object goes out of scope (i.e. loses a reference to it)

Internally, a WeakRefString{T} holds:

  • ptr::Ptr{T}: a pointer to the string data (code unit size is parameterized on T)
  • len::Int: the number of code units in the string data ``` data = Vector{UInt8}("hey there sailor")

str = WeakRefString(pointer(data), 3) @test length(str) == 3 for (i,c) in enumerate(str) @test data[i] == c % UInt8 end @test string(str) == "hey"

To facilitate using WeakRefStrings, a `WeakRefStringArray` type is provided that can simultaneously act as an `Array{WeakRefString{T}, N}` while also holding on to data references that the WeakRefStrings point to. Usage, is simple:

WeakRefStringArray(data::Vector{UInt8}, ::Type{T}, rows) => WeakRefStringArray{T, 1} WeakRefStringArray(data::Vector{UInt8}, A::Array{WeakRefString{T}, N}) => WeakRefStringArray{T, N}

In both cases, the first argument passed is the data that should be held in reference. An "empty" WeakRefString can be constructed by passing the WeakRefString element type and a number of rows, or an already constructed Array of WeakRefStrings can be passed in directly.

First Commit


Last Touched

2 months ago


49 commits