コード例 #1
0
ファイル: data.c プロジェクト: KerstenDoering/CPI-Pipeline
__inline__
static void* blockalloc_malloc(size_t n_char)
{
  struct blockalloc *p = current_block;
  size_t n = NUNITS(n_char);

  if (n_char == 0 || n > BLOCKSIZE)
    return NULL;

  if (p == NULL || p->top < n) {
    p = MALLOC(sizeof(struct blockalloc));
    assert(p != NULL);
    p->next = current_block;
    p->top = BLOCKSIZE;
    current_block = p;
  }

  p->top -= n;
  return (void *) &p->data[p->top];
}  // blockalloc_malloc()
コード例 #2
0
__inline__
static void* blockalloc_malloc(size_t n_char)
{
  struct blockalloc *p = current_block;
  size_t n;

  if (n_char == 0)
    return NULL;

  n = NUNITS(n_char);

  if (n > BLOCKSIZE)
    return NULL;

  if (p == NULL || p->top < n) {
    p = MALLOC(sizeof(struct blockalloc));
    if (p == NULL) {
      FILE* fp = fopen("/proc/self/stat", "r");
      assert(fp);
      int utime;
      int stime;
      unsigned int vsize;
      unsigned int rss;
      int result = 
	fscanf(fp, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %d %d %*d %*d %*d %*d"
	       "%*u %*u %*d %u %u", &utime, &stime, &vsize, &rss);
      assert(result == 4);
      fclose(fp);
      fprintf(stderr, "## Error: failed to allocate memory.  utime = %d, vsize = %u\n", utime, vsize);
      exit(EXIT_FAILURE);
    }
    p->next = current_block;
    p->top = BLOCKSIZE;
    current_block = p;
  }

  p->top -= n;
  return (void *) &p->data[p->top];
}  // blockalloc_malloc()