Browse Source

intptr_t is more swag

main
Titouan Rigoudy 11 years ago
parent
commit
b59bfc5582
2 changed files with 7 additions and 5 deletions
  1. +5
    -4
      yolomalloc.c
  2. +2
    -1
      yoloswag.c

+ 5
- 4
yolomalloc.c View File

@ -15,8 +15,8 @@
/* Defines */
#define YOLO_WORD (sizeof(long))
#define YOLO_DWORD (2 * sizeof(long))
#define YOLO_WORD (sizeof(intptr_t))
#define YOLO_DWORD (2 * YOLO_WORD)
#define YOLO_CHUNK 8192
/* Globals */
@ -45,12 +45,13 @@ void *yolomalloc(size_t size) {
return NULL;
}
}
int size_w = (size + (YOLO_WORD-1)) / YOLO_WORD; // size in words
int align_dw = ((size_w + 1) / 2) * 2; // round size_w to dword
intptr_t size_w = (size + (YOLO_WORD-1)) / YOLO_WORD; // size in words
intptr_t align_dw = ((size_w + 1) / 2) * 2; // round size_w to dword
void *ptr = sbrk(align_dw);
if (ptr == (void*) -1) {
return NULL;
}
yolo_end = ptr + align_dw;
return ptr;
}


+ 2
- 1
yoloswag.c View File

@ -2,13 +2,14 @@
I yoloswag.c I
*:-:-:-:-:-:-:*/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "yolomalloc.h"
int main(int argc, char **argv) {
printf("sizeof(long) = %lu\n", sizeof(long));
printf("sizeof(intptr_t) = %lu\n", sizeof(intptr_t));
for (int i = 1; i < argc; i++) {
long n = atol(argv[i]);
printf("yolomalloc(%ld) = %p\n", n, yolomalloc(n));


Loading…
Cancel
Save