title: How can I store a value at a specific location in the memory?
body: <p>Maybe this is an easy question question but I would really like to know it for sure.</p>
  
  <p>If I want to store a value, say an int, at a specific address in the memory (at the heap), how do I do it?</p>
  
  <p>Say, I want to store the int value 10 at 0x16. I guess do so by calling new or malloc: int *p=new int(10); and then I want to set the address of the stored value to 0x16. At first I thought just something like &amp;p=0x16 but this doesn't work. I need to do this to store some additional information in front of a certain value in the memory (that was previously assigned memory space by malloc or new). </p>
  
  <p>I am using linux and C++ (but C would work as well).</p>
  
  <p>What I want to achieve is: one process calls malloc with size x and I want to store a certain value (the size) in front of the allocated memory, so I can access the size later (when free is called). Since malloc was called, I know the pointer where the OS assigned space for the value and I just want to store the size of the assigned memory in the 4 bytes in front of the assigned memory. What I do (in the malloc hook that I wrote) is to assign more memory (by an internal mallok call) but I also need to be able to store this size value in the specific location.</p>
  
  <p>I am thankful for all help. </p>