<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 12-11-04 05:41 PM, Pedro Tabacof
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAAkoWuCf=2zkFscEyvNU_Mi_2rGdv82Lz84ejk1vrnLB2cHHgg@mail.gmail.com"
      type="cite">Dave, thanks a lot for your help. Indeed it was
      necessary to use new and delete instead of malloc, now my code is
      working just as I intended (in the end I used only classes to make
      the code more elegant). May I ask you two more questions? They are
      not essential but nonetheless important for a better code.
      <div>
        <br>
      </div>
      <div>1) What do you think is the best way to read a dvariable
        value from a file, if the value has been stored as a double?
        Right now I'm reading it to a regular double variable and then
        casting it to a dvariable.<br>
      </div>
    </blockquote>
    <br>
    check out ifstream and cifstream.<br>
    <br>
    with say  <br>
    <br>
           cifstream cif("filename");<br>
    <br>
    <br>
         dvariable x;<br>
    <br>
         cif >> x;<br>
    <br>
    will read in x<br>
    <br>
    <br>
    <blockquote
cite="mid:CAAkoWuCf=2zkFscEyvNU_Mi_2rGdv82Lz84ejk1vrnLB2cHHgg@mail.gmail.com"
      type="cite">
      <div>
        <div><br>
        </div>
        <div>2) This has been puzzling me: sizeof(dvariable) return 4,
          while sizeof(double) returns 8, why is dvariable size smaller
          than double?</div>
        <div><br>
        </div>
      </div>
    </blockquote>
    <br>
    <br>
    a dvariable contains a pointer which is 4 bytes onyour 32 bit
    compiler.<br>
    <blockquote
cite="mid:CAAkoWuCf=2zkFscEyvNU_Mi_2rGdv82Lz84ejk1vrnLB2cHHgg@mail.gmail.com"
      type="cite">
      <div>
        <div>Pedro.<br>
          <div><br>
            <div class="gmail_quote">
              On Sun, Nov 4, 2012 at 10:02 PM, dave fournier <span
                dir="ltr"><<a moz-do-not-send="true"
                  href="mailto:davef@otter-rsch.com" target="_blank">davef@otter-rsch.com</a>></span>
              wrote:<br>
              <blockquote class="gmail_quote" style="margin:0 0 0
                .8ex;border-left:1px #ccc solid;padding-left:1ex">
                <br>
                I was curious to see if you needed to change struct to
                class.<br>
                It appears not. But you do need to use new and delete<br>
                as this simple example shows.<br>
                <br>
                <br>
                #include <fvar.hpp><br>
                <br>
                struct mys<br>
                {<br>
                  dvariable x;<br>
                };<br>
                <br>
                main()<br>
                {<br>
                  gradient_structure gs(1000000);<br>
                <br>
                  // this will work<br>
                  mys u;<br>
                  u.x=5;<br>
                  cout << u.x << endl;<br>
                <br>
                  // this will work<br>
                  mys * pu2 = new mys;<br>
                  pu2->x=7;<br>
                  cout << pu2->x << endl;<br>
                  delete pu2;<br>
                  pu2=0;<br>
                <br>
                  // this will crash<br>
                  mys * pu=(mys*) malloc(sizeof(mys));<br>
                  pu->x=6;<br>
                  cout << pu->x << endl;
                <div class="HOEnZb">
                  <div class="h5"><br>
                    }<br>
                    <br>
                    _______________________________________________<br>
                    Users mailing list<br>
                    <a moz-do-not-send="true"
                      href="mailto:Users@admb-project.org"
                      target="_blank">Users@admb-project.org</a><br>
                    <a moz-do-not-send="true"
                      href="http://lists.admb-project.org/mailman/listinfo/users"
                      target="_blank">http://lists.admb-project.org/mailman/listinfo/users</a><br>
                  </div>
                </div>
              </blockquote>
            </div>
            <br>
            <br clear="all">
            <div><br>
            </div>
            -- <br>
            Pedro Tabacof,<br>
            Unicamp - Eng. de Computação 08.<br>
            <br>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>