-
Notifications
You must be signed in to change notification settings - Fork 41
/
ch04.txt
51 lines (40 loc) · 1.35 KB
/
ch04.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#if defined (__WINDOWS__)
# if defined LIBGDOM_STATIC
# define GDOM_EXPORT
# elif defined LIBGDOM_EXPORTS
# define GDOM_EXPORT __declspec(dllexport)
# else
# define GDOM_EXPORT __declspec(dllimport)
# endif
#else
# define GDOM_EXPORT
#endif
++ Memory Checking with Valgrind
The one add-on I really recommend for C development on Linux is Valgrind. This has a number of tools, but the one I use systematically is the Memcheck tool, which catches memory leaks and illegal accesses. Here's how I run the hello program under Valgrind:
```
valgrind --tool=memcheck --leak-check=full
--suppressions=valgrind.supp ./hello
```
Which tells me:
```
==26539== Memcheck, a memory error detector...
==26539==
Hello, World!
==26539==
==26539== HEAP SUMMARY:
==26539== in use at exit: 0 bytes in 0 blocks
==26539== total heap usage: 67 allocs, 67 frees,...
==26539==
==26539== All heap blocks were freed -- no leaks are possible
```
To suppress warnings from the way {{libzmq}} initializes memory, I create a file called {{valgrind.supp}} that contains:
[[code]]
{
<socketcall_sendto>
Memcheck:Param
socketcall.sendto(msg)
fun:send
...
}
[[/code]]
Note that running under Valgrind does slow things down. If you're expecting a certain performance from your application, don't be surprised when it crawls like a snail under Valgrind.