Skip to content

Instantly share code, notes, and snippets.

@kb10uy
Created February 3, 2016 16:10
Show Gist options
  • Save kb10uy/c5d29623edaf72f4c5aa to your computer and use it in GitHub Desktop.
Save kb10uy/c5d29623edaf72f4c5aa to your computer and use it in GitHub Desktop.
とりあえずメモリを埋めたい人用
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#define BLOCK_SIZE 1048576U
uint32_t xor128(void);
int main(void) {
uint32_t count = 0;
printf("started!\n");
printf("block size is %dbyte\n", BLOCK_SIZE);
do {
uint8_t *np;
np = (uint8_t*) malloc(BLOCK_SIZE);
if (np == NULL) {
printf("failed!\n");
uint64_t all = BLOCK_SIZE * count;
printf("%lldbytes memory allocated\n", all);
return -1;
}
for(int i = 0; i < BLOCK_SIZE; i++) {
uint32_t rp = xor128() % BLOCK_SIZE;
*(np + rp) = xor128() & 0xff;
}
count++;
printf("%dblocks allocated!\n", count);
} while(count);
return 0;
}
uint32_t xor128(void) {
static uint32_t x = 123456789;
static uint32_t y = 362436069;
static uint32_t z = 521288629;
static uint32_t w = 88675123;
uint32_t t;
t = x ^ (x << 11);
x = y; y = z; z = w;
return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment