Skip to content

Instantly share code, notes, and snippets.

@sgielen
Created April 21, 2014 13:13
Show Gist options
  • Save sgielen/11142380 to your computer and use it in GitHub Desktop.
Save sgielen/11142380 to your computer and use it in GitHub Desktop.
Need some resident memory usage? This cpp file constantly allocates sizeof(uint64_t)+sizeof(void*) of it and tries to keep it out of swapped memory.
#include <stdint.h>
#include <stdio.h>
struct node_t {
node_t() : i(0), previous(0) {}
node_t(node_t *previous) : i(previous->i + 1), previous(previous) {}
uint64_t i;
node_t *previous;
};
int main() {
node_t *last = new node_t();
while(1) {
last = new node_t(last);
if((last->i % 10000) == 0) {
printf("%8lu", last->i);
node_t *current = last;
while(current->previous != 0) {
current = current->previous;
}
printf("\n");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment