1 /* memtest.c --
2  * Copyright 2018 Aleksey Cheusov (vle@gmx.net)
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  */
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 
29 #include "maa.h"
30 
main(int argc,char ** argv)31 int main(int argc, char** argv)
32 {
33 	mem_Object objects = NULL;
34 	int *one;
35 	int *two;
36 	int *three;
37 
38 	maa_init(argv[0]);
39 
40 	objects = mem_create_objects(sizeof(int));
41 
42 	one = (int *) mem_get_object(objects);
43 	*one = 1;
44 
45 	two = (int *) mem_get_object(objects);
46 	*two = 2;
47 
48 	printf("obj1=%d\n", *one);
49 	printf("obj2=%d\n", *two);
50 
51 	mem_print_object_stats(objects, stdout);
52 
53 	mem_free_object(objects, two);
54 
55 	mem_print_object_stats(objects, stdout);
56 
57 	*two = 22;
58 	two = (int *) mem_get_object(objects);
59 	printf("obj2_reused=%d\n", *two);
60 	mem_print_object_stats(objects, stdout);
61 
62 	mem_free_object(objects, two);
63 	two = (int *) mem_get_empty_object(objects);
64 	printf("obj2_zeroed=%d\n", *two);
65 	*two = 2;
66 	mem_print_object_stats(objects, stdout);
67 
68 	three = (int *) mem_get_empty_object(objects);
69 	*three = 3;
70 
71 	printf("obj1=%d\n", *one);
72 	printf("obj2=%d\n", *two);
73 	printf("obj3=%d\n", *three);
74 
75 	mem_print_object_stats(objects, stdout);
76 
77 	mem_destroy_objects(objects);
78 
79 	maa_shutdown();
80 	return 0;
81 }
82