DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Understanding & Using C++

  1. #1
    Jama Guest

    Understanding & Using C++


    1 - const int arSize=4096;
    2 - double *d = new double[arSize];
    3 - d[0]= 1.; d[arSize-1] = 2.; // for committing memory

    I read the above code from someone's code and I understand everything except
    the comment "// for committing memory"
    I thought we committed memory when we declared the pointer d at the second
    line.
    My understanding is that we allocated memory of size arSize at line 2 and
    line 3 and the following comment are unnecessary. Please explain.
    Thanks


    Jama


  2. #2
    Steve F Guest

    Re: Understanding & Using C++


    Jama, you are correct. I think what the other programmer had in mind was to
    force the OS to ensure that RAM as opposed to virtual address space was backing
    the buffer. For all practical purposes line 3 is useless as you said because:
    1) The operating system can page the memory out to disk at any time.
    2) The virtual address space (if it is not immediatly commited) is automatically
    commited by the OS.
    3) Accessing the start and end of a buffer doesn't ensure the entire buffer
    is in RAM because the buffer can span more than 2 physical memory pages anyway
    (Under Win32 on a PC this buffer would span 8 pages minimum)

    Steve

    "Jama" <jc64_23@yahoo.com> wrote:
    >
    >1 - const int arSize=4096;
    >2 - double *d = new double[arSize];
    >3 - d[0]= 1.; d[arSize-1] = 2.; // for committing memory
    >
    >I read the above code from someone's code and I understand everything except
    >the comment "// for committing memory"
    >I thought we committed memory when we declared the pointer d at the second
    >line.
    >My understanding is that we allocated memory of size arSize at line 2 and
    >line 3 and the following comment are unnecessary. Please explain.
    >Thanks
    >
    >
    >Jama
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center