stringnogc 0.0.3

GC-free string and writeln


To use this package, run the following command in your project's root directory:

stringnogc

  • Experimental @nogc nothrow string and writeln.
  • You have two options for memory management.
  • 1) dString!aumem runs like std::string of cpp which is scoped and copied on function calls unless you pass it as reference.
  • 2) Manage it manually using dString!manmem
  • supports concatenation: `auto cat = _ds("pac", 'k', " ", "those values: ", 3.7, " ", 0.5f, " ", 1024, " please!");`
  • writeln2 runs with structs recursively;

Example:


import stringnogc;

alias dStringm = dString!manmem;
alias dStringa = dString!aumem;

void main() @nogc nothrow {

    struct S1 {float a; int b; double c; string d; int e;}
    struct S2 {int a; uint b; char c; string d; S1 s;}
    
    S1 s1 = S1(0.1f, 5, 1.5, "test", 16);
    S2 s2 = S2(0, 1, 'x', "hello", s1);

    writeln2(s2, "::", "a string");
    
    dStringa str2 = "a GC-free ";
    dStringm str1 = "This is ";
    string str3 = "string implementatio";

    str1 ~= str2;
    str1 ~= str3;
    str1 ~= 'n';
    str1 ~= "!";
    
    auto strcopy = str1.copy;
    
    scope(exit){
        str1.freeStr;
        //str2.freeStr; // note that the memory with str2 is managed automatically
        strcopy.freeStr;
    }
    
    assert(strcopy == "This is a GC-free string implementation!");
    assert(strcopy.str == "This is a GC-free string implementation!");

    writeln2(str1);

    auto something = "those values: ";
    auto cat = _ds("pac", 'k', " ", something, 3.7, " ", 0.5f, " ", 1024, " please!"); // returns dString!manmem as default

    assert(cat == "pack those values: 3.700000 0.500000 1024 please!");
    assert(cat.length == 49); // must be true for ascii only
    
    writeln2(cat);
    cat.freeStr;
}

Authors:
  • Ferhat Kurtulmuş
Dependencies:
none
Versions:
0.0.3 2019-Nov-13
0.0.2 2019-Nov-10
0.0.1 2019-Nov-09
Show all 3 versions
Download Stats:
  • 1 downloads today

  • 4 downloads this week

  • 4 downloads this month

  • 4 downloads total

Score:
0.4
Short URL:
stringnogc.dub.pm