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.4 and current 0.5 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
  • ind::Int: a field that can be used to store an integer, like an index into an array; this can be helpful in certain cases when the underlying source may need to move around (which would invalidate the WeakRefString's ptr field), a new WeakRefString can created using the same offset into the parent data as the old one. ``` data = "hey there sailor".data

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"

First Commit


Last Touched

about 1 year ago


25 commits