www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Debugging compile time memory usage

reply Kamil Koczurek <koczurekk gmail.com> writes:
I recently wrote a brainfuck compiler in D, which loads the BF 
source at compile time, performs some (simple) optimizations, 
translates everything to D and puts it into the source code with 
a mixin.

I did manage to get some pretty good performance, but for some 
programs in brainfuck I have to use LDC instead of DMD because 
the latter runs out of memory. Is there a way for me to optimize 
my code in such a way that DMD will be able to compile it?

D code: https://pastebin.com/fg1bqwnd
BF program that works: 
https://github.com/erikdubbelboer/brainfuck-jit/blob/master/mandelbrot.bf
BF program that makes DMD crash: 
https://github.com/fabianishere/brainfuck/blob/master/examples/hanoi.bf

After putting BF code in code.bf and D in main.d, I compile it 
with the following command: dmd main.d -J./

Error msg: unable to fork: Cannot allocate memory
DMD version: DMD64 D Compiler v2.080.0-dirty
Jun 24 2018
next sibling parent Stefan Koch <uplink.coder googlemail.com> writes:
On Sunday, 24 June 2018 at 14:16:26 UTC, Kamil Koczurek wrote:
 I recently wrote a brainfuck compiler in D, which loads the BF 
 source at compile time, performs some (simple) optimizations, 
 translates everything to D and puts it into the source code 
 with a mixin.

 I did manage to get some pretty good performance, but for some 
 programs in brainfuck I have to use LDC instead of DMD because 
 the latter runs out of memory. Is there a way for me to 
 optimize my code in such a way that DMD will be able to compile 
 it?

 D code: https://pastebin.com/fg1bqwnd
 BF program that works: 
 https://github.com/erikdubbelboer/brainfuck-jit/blob/master/mandelbrot.bf
 BF program that makes DMD crash: 
 https://github.com/fabianishere/brainfuck/blob/master/examples/hanoi.bf

 After putting BF code in code.bf and D in main.d, I compile it 
 with the following command: dmd main.d -J./

 Error msg: unable to fork: Cannot allocate memory
 DMD version: DMD64 D Compiler v2.080.0-dirty
Check out https://github.com/UplinkCoder/bf-ctfe. It uses all tricks which I know to use the least amount of memory. (Which admittedly still is a lot) Other then that. you'll have to wait for newCTFE to be stable enough for me to give green light for merging.
Jun 24 2018
prev sibling parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Sunday, 24 June 2018 at 14:16:26 UTC, Kamil Koczurek wrote:
 I recently wrote a brainfuck compiler in D, which loads the BF 
 source at compile time, performs some (simple) optimizations, 
 translates everything to D and puts it into the source code 
 with a mixin.

 I did manage to get some pretty good performance, but for some 
 programs in brainfuck I have to use LDC instead of DMD because 
 the latter runs out of memory. Is there a way for me to 
 optimize my code in such a way that DMD will be able to compile 
 it?

 D code: https://pastebin.com/fg1bqwnd
 BF program that works: 
 https://github.com/erikdubbelboer/brainfuck-jit/blob/master/mandelbrot.bf
 BF program that makes DMD crash: 
 https://github.com/fabianishere/brainfuck/blob/master/examples/hanoi.bf

 After putting BF code in code.bf and D in main.d, I compile it 
 with the following command: dmd main.d -J./

 Error msg: unable to fork: Cannot allocate memory
 DMD version: DMD64 D Compiler v2.080.0-dirty
If you were able to compile it with LDC and not DMD, then that is most likely due to the LDC executable being 64-bit (limited to available system RAM+swaps) and the DMD executable being 32-bit (limited to 4GB). If you want to use DMD, build a 64-bit version yourself and complain on general that the releases are not 64-bit.
Jun 25 2018
parent Bauss <jj_1337 live.dk> writes:
On Tuesday, 26 June 2018 at 00:59:24 UTC, Nicholas Wilson wrote:
 On Sunday, 24 June 2018 at 14:16:26 UTC, Kamil Koczurek wrote:
 [...]
If you were able to compile it with LDC and not DMD, then that is most likely due to the LDC executable being 64-bit (limited to available system RAM+swaps) and the DMD executable being 32-bit (limited to 4GB). If you want to use DMD, build a 64-bit version yourself and complain on general that the releases are not 64-bit.
Is there a specific reason why DMD isn't shipped as 64bit by default? Literally most machines are 64bit these days, so why do we limit ourselves to 32bit?
Jun 25 2018