Mercurial > projects > dstress
comparison run/new_04.d @ 889:b3da1b510a19
div. memory management
author | thomask |
---|---|
date | Mon, 06 Mar 2006 08:01:27 +0000 |
parents | 32f7f8ce5e51 |
children |
comparison
equal
deleted
inserted
replaced
888:a995eae8e75c | 889:b3da1b510a19 |
---|---|
2 // $Date$ | 2 // $Date$ |
3 // $Author$ | 3 // $Author$ |
4 | 4 |
5 module dstress.run.new_04; | 5 module dstress.run.new_04; |
6 | 6 |
7 extern(C) void* malloc(size_t); | 7 char[] status; |
8 int count; | |
8 | 9 |
9 byte a; | 10 class C{ |
10 | |
11 class MyClass{ | |
12 byte b; | 11 byte b; |
13 | 12 |
14 this(byte c){ | 13 this(byte c){ |
15 b=c; | 14 b = c; |
16 } | 15 } |
17 | 16 |
18 new(size_t size, byte blah){ | 17 new (size_t i, char[] msg){ |
19 void* v=malloc(size); | 18 status = msg; |
20 if(v is null){ | 19 count++; |
21 throw new Exception(null); | 20 |
22 } | 21 return (new ubyte[i]).ptr; |
23 a=blah; | |
24 return v; | |
25 } | 22 } |
26 } | 23 } |
27 | 24 |
28 int main(){ | 25 int main(){ |
29 MyClass m = new(21) MyClass(12); | 26 if(status.length != 0){ |
30 assert(m.b==12); | 27 assert(0); |
31 assert(a==21); | 28 } |
29 | |
30 C c; | |
31 | |
32 if(status.length != 0){ | |
33 assert(0); | |
34 } | |
35 | |
36 if(count != 0){ | |
37 assert(0); | |
38 } | |
39 | |
40 if(c !is null){ | |
41 assert(0); | |
42 } | |
43 | |
44 c = new("abc") C(-4); | |
45 | |
46 if(status != "abc"){ | |
47 assert(0); | |
48 } | |
49 | |
50 if(count != 1){ | |
51 assert(0); | |
52 } | |
53 | |
54 if(c is null){ | |
55 assert(0); | |
56 } | |
57 | |
58 if(c.b != -4){ | |
59 assert(0); | |
60 } | |
61 | |
32 return 0; | 62 return 0; |
33 } | 63 } |