On Thursday, 21 May 2020 at 15:09:57 UTC, Steven Schveighoffer
wrote:
On 5/20/20 10:50 PM, data pulverizer wrote:
how do you allocate/free memory without using the garbage
collector?
Use C malloc and free.
Does allocating and freeing memory using `GC.malloc` and
`GC.free` avoid D's garbage
import std.stdio;
import automem;
import std.experimental.allocator.mallocator : Mallocator;
interface IGetInt
{
@nogc int GetInt();
}
class Foo : IGetInt
{
@nogc int GetInt()
{
return 42;
}
}
@nogc void main()
{
auto foo = Unique!(Foo, Mallocator).construct;
I saw docs for std.experimental.allocator and also had found
automem library(https://code.dlang.org/packages/automem) for c++
style memory management via smartpointers.
From GC documentation std.experimental.allocator can not be used
for:
NewExpression
Array appending
Array
Are you looking for parallel?
http://dlang.org/library/std/parallelism/parallel.html
I have seen this, but I'm not sure how to use it.
Maybe:
float[][] maps = new float[#threads][resolution * resolution];
foreach(i, ref elem; parallel(maps)){
elem = generateTerrain(...);
}
Does this
Hello D-World,
I've written a small terraingenerator in D based on the
Hill-Algorithm.
To generate a terrain I only need to call the method
generateTerrain(...) which returns a float-Array containing the
height of each pixel (2D Array mapped with a 1D array with length
resolution^2).