stringnogc 0.0.4
GC-free string and writeln
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
stringnogc
- @nogc nothrow betterC string.
- 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 (not betterC yet);
Client programs can use subConfigurations to compile with betterC:
"subConfigurations": {
"stringnogc": "betterC"
},
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;
}
- Registered by Ferhat Kurtulmuş
- 0.0.4 released 9 months ago
- aferust/stringnogc
- boost
- Copyright © 2019, Ferhat Kurtulmuş
- Authors:
- Dependencies:
- none
- Versions:
-
0.0.4 2020-Apr-11 0.0.3 2019-Nov-13 0.0.2 2019-Nov-10 0.0.1 2019-Nov-09 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
9 downloads total
-
- Score:
- 0.3
- Short URL:
- stringnogc.dub.pm