This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import core.sys.windows.windows, core.stdc.stdlib, | |
| std.stdio, std.datetime; | |
| //pragma(mangle, "_QueryWorkingSet@12") | |
| extern(Windows) BOOL QueryWorkingSet(HANDLE hProcess,PVOID pv,DWORD cb); | |
| void main() | |
| { | |
| // map 512mb, obviously 32bit sucks, as I couldn't map more | |
| uint SIZE = 2^^29; | |
| auto mapping = CreateFileMappingA(INVALID_HANDLE_VALUE, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scopebuf; | |
| //import std.buffer.scopebuffer; | |
| import std.datetime, std.conv, std.stdio, std.exception; | |
| int do_build(int n) | |
| { | |
| char[80] store = void; | |
| auto buf = scopeBuffer(store[]); | |
| //scope(exit) buf.free(); | |
| for(int i=0; i<n;i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| New API for std.regex was introduced. The old API that had its operation mode dependent on "g" (=global) flag was too confusing and error prone. Moreover in some cases it was already being overrided by a function such as by splitter with regex. | |
| New version ties the operation to the function in question, thus being simpler to understand without extra context. Compare 2 samples. | |
| Before: | |
| --- | |
| void main() | |
| { | |
| import std.regex, std.algorithm, std.range, std.stdio, std.string; | |
| auto m = "3.141592".match(`(\d+)\.(\d+)`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Simple threaded-code interpreter | |
| * Practical on the follwoing compiler(s)/options | |
| * gdc -O2 and above (tested on venerable 4.6) | |
| * ldc -O1 and above (tested with LLVM 3.3) | |
| * Not usable on dmd - doesn't optimize tail-call to jump | |
| */ | |
| import std.typecons; | |
| struct OpCode{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.regex; | |
| import core.stdc.stdio; | |
| import core.stdc.string; | |
| import std.string; | |
| import std.stdio : writefln, writef; | |
| /* | |
| Parses mail logs like this line: | |
| Nov 1 19:37:59 themailhost sendmail[10620]: [ID 801593 mail.info] pA20bx2u010620: | |
| from=<[email protected]>, size=6988, class=0, nrcpts=2, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.range, std.traits, std.stdio, std.format, std.digest.sha; | |
| auto demux(Output...)(Output sinks) | |
| { | |
| static struct Demux | |
| { | |
| Output outs; | |
| this(Output outs) | |
| { | |
| this.outs = outs; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.traits, std.utf : UTFException; | |
| uint stride(S)(auto ref S str, size_t index) | |
| if (is(S : const char[]) || | |
| (isRandomAccessRange!S && is(Unqual!(ElementType!S) == char))) | |
| { | |
| immutable c = str[index]; | |
| if (c < 0x80) | |
| return 1; | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///Written in the D programming language | |
| // Bench built-in array append, std.array.Appender | |
| // and custom virtual-memory aware VirtualArray in terms of | |
| // memory usage and the time taken | |
| // to append up to X megabytes using different chunk sizes: | |
| // 16 bytes, 64bytes, 256 bytes and 16Kb at a time. | |
| // pass this version to take insert readln's |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.traits, std.exception, core.stdc.stdlib; | |
| version(unittest) import std.typetuple; | |
| // preferred size of one Builder chunk | |
| // not too small (to not waste memory with allocation padding, pointer link etc.) | |
| // and not too big (good fit for CPU cache, less per-thread memory usage) | |
| private enum builderChunkSize = 2^^14 - (void*).sizeof; | |
| // TLS chunk cache for builder |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.concurrency, std.stdio, std.container, core.sync.mutex, core.thread; | |
| struct Synced(T) if(!(is(T == class))) | |
| { | |
| private: | |
| shared T* payload; | |
| __gshared Mutex mut; //mutex should have worked as shared | |
| public this(Args)(Args args...){ |
NewerOlder