Uncompress order.c Compile rand_malloc.c with GNU GCC compiler.
Run on command line:
1st argument is seed for pseudo random number generator (optional)
2nd argument is number of malloc blocks to try (default 1)
Example:
./rand_malloc 1801513025 3502077
expected output:
./rand_malloc $Revision: 1.36 $ seed=1801513025 3502077 0 10000000x20 3502077 glibc 2.34 stable
settime index 11991991 out of bounds 10000000 (not all heap will be freed)
10000001 steps (maxwidth 12, last random number 539682942)
Last free at 11999310, malloc event limit 3502077
Total allocated 396816157, 3502077 mallocs 3463129 frees, Max_malloc 34411437 bytes, 10158805 still on heap
peak_malloc 37216256 bytes
10000001 is the number of simulated ticks (each malloc is one tick). In this example, limited by internal SIZE (10,000,000).
Max_malloc 34411437 is the peak number of useful bytes (created by malloc).
peak_malloc 37216256 is the maximum size of the heap (as reported by mallinfo2).
396816157 is the total number of bytes allocated.
3502077 is the number of times malloc is called (given on the command line). Notice, in this run, although we pass the peak heap used, we do not have enough space to complete all the free() calls (only 3463129 malloc blocks life times expire). Thus 10,158,805 bytes are still allocated in the heap when the program ends.
maxwidth 12 says in atleast one simulation step 12 malloc blocks expired at the same time (limited by WIDTH 20).
The last psuedo random number is reported in case in future different implementations produce different values for the same seed.
order.c is an #include file specifying the calls to malloc. To save space it is compressed by gzip to give order.c.gz use gunzip order.c.gz before compiling rand_malloc.c
dh_view.html (and dh_view.css and dh_view.js) is released with valgrind to visualise output generated by valgrind's DHAT tool. The default version of dh_view.js combines data for less important malloc calls. Here dh_view.js treats all malloc blocks as significant. The gawk script dhat_summary.awk is used to create order.c
Note in different releases of valgrind the dhat.dat.<pid> file may have different formats.
rand_malloc will be presented at UKCI 2025 the 24th UK Workshop in Computational Intelligence, September 3-5, 2025, Napier University, https://ukci2025.napier.ac.uk/