]> git.llucax.com Git - personal/website.git/blob - source/blog/posts/2010/08/14-memory-allocation/bigarr.d
blog: Publish post about LANGUAGE
[personal/website.git] / source / blog / posts / 2010 / 08 / 14-memory-allocation / bigarr.d
1 // Written by Babele Dunnit <babele.dunnit@gmail.com>
2 // Found at http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=54084
3 // Sightly modified by Leandro Lucarella <llucax@gmail.com>
4 // (some readability improvements and output removed)
5
6 const IT = 300;
7 const N1 = 20_000;
8 const N2 = 40_000;
9
10 class Individual
11 {
12         Individual[20] children;
13 }
14
15 class Population
16 {
17
18         void grow()
19         {
20                 foreach(inout individual; individuals)
21                 {
22                         individual = new Individual;
23                 }
24         }
25
26         Individual[N1] individuals;
27 }
28
29 version = loseMemory;
30
31 int main(char[][] args)
32 {
33
34         Population testPop1 = new Population;
35         Population testPop2 = new Population;
36
37         Individual[N2] indi;
38
39         for(int i = 0; i < IT; i++)
40         {
41                 testPop1.grow();
42                 testPop2.grow();
43
44                 version (loseMemory){
45                         indi[] = testPop1.individuals ~ testPop2.individuals;
46                 }
47
48                 version (everythingOk){
49                         indi[0..N1] = testPop1.individuals;
50                         indi[N1..N2] = testPop2.individuals;
51                 }
52         }
53
54         return 0;
55 }
56