title: MemSet & MemCopy
body: <p>I'm writing a memory allocator, and I need a way to store an integer inside of a chunk of memory.  This integer will represent the size of the block so I can navigate to the end given the pointer to the beginning.</p>
  
  <p>Here's my test example:</p>
  
  <p>// EDIT: Declared space for testInt
      int* testInt = new int;</p>
  
  <pre><code>head_ptr = (char*) malloc(4*1024*1024); // Allocate 4MB
  
  // EDIT: Should have used std::fill and std::copy
  memset(head_ptr,23,sizeof(int)); // Set Address head_ptr = 12345
  
  memcpy(testInt,head_ptr,sizeof(int)); // Set testInt = head_ptr
  
  printf("testInt = %i",testInt);
  </code></pre>
  
  <p>This throws a segmentation fault on the second to last line.  </p>
  
  <p>Does what I'm trying to do make sense?</p>
  
  <p>If so, what is the correct approach?</p>
  
  <p><strong>Thank you so much everyone for your help!! Problem solved :-)</strong></p>