virtmem
virtual memory library for Arduino
utils.h
1 #ifndef VIRTMEM_UTILS_H
2 #define VIRTMEM_UTILS_H
3 
4 #ifndef ARDUINO
5 #include <assert.h>
6 #define ASSERT assert
7 #else
8 #include <Arduino.h>
9 
10 #if 0
11 // From https://forum.pjrc.com/threads/23256-Get-Free-Memory-for-Teensy-3-0?p=34242&viewfull=1#post34242
12 inline void freeRam(const char *msg)
13 {
14  uint32_t stacktop;
15  uint32_t heaptop;
16 
17  // current position of the stack.
18  stacktop = (uint32_t)&stacktop;
19 
20  // current position of heap.
21  void *top = malloc(1);
22  heaptop = (uint32_t)top;
23  free(top);
24 
25  // The difference is the free, available ram.
26  Serial.print(msg); Serial.println(stacktop - heaptop);
27 
28 // return stacktop - heaptop;
29 }
30 #endif
31 
32 #if 0
33 #define ASSERT(x) \
34  do \
35  { \
36  if ((x)) ; else \
37  { \
38  Serial.print("Assertion failed!: "); Serial.print(#x); Serial.print(" @ "); Serial.print(__FILE__); Serial.print(":"); Serial.println(__LINE__); \
39  while (true) \
40  ; \
41  } \
42  } \
43  while (false);
44 #else
45 #define ASSERT(x)
46 #endif
47 
48 #endif
49 
50 namespace virtmem {
51 
52 namespace private_utils {
53 
54 template <typename T> T minimal(const T &v1, const T &v2) { return (v1 < v2) ? v1 : v2; }
55 template <typename T> T maximal(const T &v1, const T &v2) { return (v1 > v2) ? v1 : v2; }
56 
57 template <typename T> struct AntiConst { typedef T type; };
58 template <typename T> struct AntiConst<const T> { typedef T type; };
59 
60 }
61 
62 }
63 
64 #endif // VIRTMEM_UTILS_H
contains all code from virtmem
Definition: base_alloc.cpp:22