Managing memory usage at Compile Time with DMD

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 9 03:00:39 PDT 2015


On 9/04/2015 9:49 p.m., 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).
>
> 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?
>
> 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.
>
> Thanks!

My recommendation is to pregenerate this with a separate file.
So generator.d -> mydata.d
Since mydata.d won't need to be updated often, only recompile it 
shouldn't be an issue.


More information about the Digitalmars-d-learn mailing list