Lolly 1.4.28
Loading...
Searching...
No Matches
fast_alloc_test.cpp
Go to the documentation of this file.
1#include "a_lolly_test.hpp"
2#include "fast_alloc.hpp"
3#include "tm_timer.hpp"
4
5struct Complex {
6public:
7 double re, im;
8 Complex (double re_, double im_) : re (re_), im (im_) {}
9 Complex () : re (0.5), im (1.0) {}
11};
12
13TEST_CASE ("test for memory leaks") {
14 char* p_char= tm_new<char> ('a');
15 CHECK (*p_char == 'a');
16
17 p_char= tm_new<char> ('b');
18 CHECK (*p_char == 'b');
19
20 *p_char= 'c';
21 CHECK (*p_char == 'c');
22
24
25 char* q_char= tm_new<char> ('z'); // here p_char is modified to 'z'
26
27 // *p_char= 'c'; // behavior of this code is unspecified, DO NOT DO THIS!
28}
29
31
32TEST_CASE ("test basic data types") {
33
34 char* ch;
35 int* in;
36 long* lo;
37 double* dou;
38
39 ch = tm_new<char> ();
40 in = tm_new<int> ();
41 lo = tm_new<long> ();
43
44 tm_delete (ch);
45 tm_delete (in);
46 tm_delete (lo);
47 tm_delete (dou);
48}
49
50TEST_CASE ("test class") {
51 Complex* p_complex= tm_new<Complex> (35.8, 26.2);
53}
54
55TEST_CASE ("test tm_*_array") {
58#ifdef OS_WASM
59 const size_t size_prim= 200, size_complex= 100;
60#else
61 const size_t size_prim= 20000000, size_complex= 5000000;
62#endif
67}
68
69#ifndef OS_WASM
70TEST_CASE ("test large bunch of tm_*") {
71 const int bnum= 100000;
72 int* volume[bnum];
73 for (int i= 0; i < bnum; i++) {
74 volume[i]= tm_new<int> (35);
75 }
76 for (int i= 0; i < bnum; i++) {
77 tm_delete (volume[i]);
78 }
79}
82#endif
83
84TEST_CASE ("test large bunch of tm_*_array with class") {
85
86#ifdef OS_WASM
87#define NUM 100
88#else
89#define NUM 10000
90#endif
92 for (int i= 0; i < NUM; i++) {
94 }
95 for (int i= 0; i < NUM; i++) {
97 }
98}
99
The list class represents a linked list.
Definition list.hpp:48
void tm_delete(C *ptr)
void tm_delete_array(C *Ptr)
#define NUM
#define TEST_MEMORY_LEAK_RESET
#define TEST_MEMORY_LEAK_INIT
#define TEST_MEMORY_LEAK_ALL
TEST_CASE("test for operator+= and advance()")
Complex(double re_, double im_)