Skip to content

Instantly share code, notes, and snippets.

View ZacAttack's full-sized avatar

Zac Policzer ZacAttack

  • LinkedIn
  • San Francisco
View GitHub Profile
@ZacAttack
ZacAttack / heap-fragmentor.cpp
Created January 15, 2021 22:06
This program shows you how your process heap can become fragmented under some memory allocators!
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
// Define constants to make sure strings are not allocated at the top of the heap
#define HIT_ENTER "Press Enter to continue...\n"
#define ALLOCATED "500k 5KB chunks were just provisioned\n"
#define FREED "The first allocations were just free()'d.\n"
@ZacAttack
ZacAttack / preload.sh
Created January 15, 2021 22:16
Preload and configure jemalloc
MALLOC_CONF="dirty_decay_ms:0" LD_PRELOAD=/usr/local/lib/libjemalloc.so ./memory-demo
@ZacAttack
ZacAttack / gdb-summary.txt
Created January 15, 2021 22:17
Output of gdb-heap
------------- Summary -------------
Total Free Chunked Memory:4365301296
Total Chunked Avbl Memory:17963147264
Total Memory Utilization:76%