title: C++ Trying to do some kind of VARCHAR
body: <p>I am writing a small database manager, but I am having trouble doing something like VARCHAR type.</p>
  
  <p><strong>It should work like this:</strong> I have a 3 digits word, say "RPG", it should allocate enough size to put there RPG\0.</p>
  
  <p><strong>What is happening:</strong> It doesn't really matter if I use new, malloc(3), malloc(1), malloc(sizeof(char)*"RPG".size()), I can always use a much bigger region in memory. I tried checking it with malloc_size() and it always returns 16.</p>
  
  <p>How can I do something that will allocate just enough space?</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>There's no specific codes, I'm trying things out and trying to figure how to do a char of varying size, but it would be something like this:</p>
  
  <pre><code>char * myChar1 = (char*)malloc(sizeof(unsigned short int));
  size_t howManyBytes = malloc_size(myChar1);
  cout &lt;&lt; "howManyBytes: " &lt;&lt; howManyBytes &lt;&lt; " bytes" &lt;&lt; ends; //should say 2, instead it says 16
  strcpy(myChar1,"HELLO HOW ARE YOU"); //shouldn't write the entire sentence as its bigger than 2 bytes
  cout &lt;&lt; "MYCHAR1: " &lt;&lt; myChar1 &lt;&lt; endl; //string
  cout &lt;&lt; "&amp;MYCHAR1: " &lt;&lt; &amp;myChar1 &lt;&lt; endl; //adress
  cout &lt;&lt; "*MYCHAR1: " &lt;&lt; *myChar1 &lt;&lt; endl; //first letter
  </code></pre>