title: How do I put this struct into this dynamically allocated space?
body: <p>I am working on a project that implements the buddy allocation algorithm in C. Using mmap(), I allocated a space of 1GB of continuous memory. It looks like this: </p>
  
  <pre><code>  char * base = mmap(NULL, MAX_MEM, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
  </code></pre>
  
  <p>I have a struct that I am trying to place into that space. The struct looks like this:</p>
  
  <pre><code>typedef struct Node {
      unsigned char header;
      struct Node *next;
      struct Node *prev;
  
  }node;
  </code></pre>
  
  <p>I am unsure how to get a node to go into that spot. I tried the code below because I didn't want to put the node at the very beginning, but when I print out the pointer they show much different spots</p>
  
  <pre><code>void *ptr = (struct Node *) base + 512;
  printf("base: %p\n", base);
  printf("ptr: %p\n", ptr);
  </code></pre>
  
  <p>My terminal window prints out this: </p>
  
  <pre><code>base: 0x102ef1000
  ptr: 0x102ef4000
  </code></pre>
  
  <p>But this doesn't seem right because the pointers are 12288 spaces away from each other in memory instead of just 512. What am I doing wrong?</p>