On Thursday, 9 April 2015 at 09:49:39 UTC, wobbles wrote:
So, I'm writing a poker AI bot. The idea was to generate a
lookup table of all the poker hands using CTFE so runtime can
be as quick as possible (as the bot has a very small amount of
time to act).
There are a LOT of calculations though, many millions of
combinations.
During complation, this is consuming inordinate amounts of
memory, 16GB+ (which is all the RAM on my machine + some swap
space).
Unfortunately, the current implementation of CTFE is not very
memory-friendly. This is being worked on.
I'm wondering is there any techniques to freeing some memory
used by the compiler so it can be reused?
Are malloc and free usable at compile time maybe?
No, they are not.
Another possibilty I was looking at was to write a tool that
will spit out all combinations at runtime, and then import
these back into the bot at compile time to build a lookup table
that way.
This is probably the most practical solution for the time being.
Some advice:
1. writeln, format and friends print most values (e.g. arrays) in
a syntax close to D's, which means you should be able to take the
output and paste it into a D program.
2. You can use import expressions and mixin expressions to import
constant values from files:
http://dlang.org/expression.html#ImportExpression
http://dlang.org/expression.html#MixinExpression