Turning off the D garbage collector

前端 未结 4 959
清酒与你
清酒与你 2021-01-30 23:20

I\'m a C++ programmer thats considering using D for a personal project I want to play around with. I was wondering if there\'s a way to completely disable the garbage collector

4条回答
  •  广开言路
    2021-01-30 23:28

    If you want to use malloc and free use std.c.stdlib. GC will never touch these. std.gc has all the stuff you will need for memory management including disable().

    GC isn't a bad thing though. Most if not nearly all libraries in D will have somewhere in the code where memory is not explicitly deleted so it won't make you a hero to have it allways off but ok if you have some critical performance requirement.

    GC makes everything a lot more productive like array slicing and creating new objects in parameters without having the caller store a reference anywhere to them. Good code is a lot less of it and with GC code becomes a lot smaller.

提交回复
热议问题