continous memory

This is a discussion on continous memory within the C++ Programming forums, part of the General Programming Boards category; hi, i've read that calling malloc or new dosn't mean you'll get continous memory allocated to your program. this is ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    50

    continous memory

    hi,

    i've read that calling malloc or new dosn't mean you'll get continous memory allocated to your program. this is a bit of a problem in a program i'm writing, where being able to use pointer additio would simplify things. can anyone tell me how continuous memory can be acquired in a win32 environment ? its no big deal if it only works on the WIN32_NT platform

    thanks in advance.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    You don't have to worry about it - the OS will take care of it in a way that is invisible to your program. That's the beauty of protected-mode operating systems.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > i've read that calling malloc or new dosn't mean you'll get continous memory allocated to your program
    Get a better source of information then - it's wrong. The memory in any single block you get with malloc/new will be contiguous.

    However, given
    p = malloc(10);
    q = malloc(10);
    You can't make any statement about the relationship between p and q
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    50
    >> i've read that calling malloc or new dosn't mean you'll get continous memory allocated to your program
    >Get a better source of information then - it's wrong. The memory in any single block you get with malloc/new will be contiguous.

    guess thats the trouble with the internet . thanks to both of you for your help

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    It's definitly continous in virtual memory, and that means all practical purposes, but the implementation can do whatever it wants to with physical memory?

  6. #6
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    If you need a continuous block of memory, allocate everything you need at once, with one new statement.

    If you allocate it using several new statements, it's not guaranteed to be continuous.

    (Yes Salem, I know I just repeated what you said)
    Away.

  7. #7
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Or you can overload the new operator to create a pool system.

    okinrus, well, if you want more informations about how the memory is used and the relationship between physical and virtual memory, you should go to the Intel developers site and get the 3rd manual of the IA-32. Because, there are paging, segmentation and other stuffs like that which make it difficult to give an exact answer here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. available memory from task manager
    By George2 in forum Tech Board
    Replies: 10
    Last Post: 01-18-2008, 01:32 AM
  2. Replies: 4
    Last Post: 01-13-2008, 01:14 AM
  3. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 12:57 AM
  4. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  5. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 01:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21